Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Seq Optimizations #922

Merged
merged 4 commits into from
Jun 21, 2024
Merged

Conversation

1eyewonder
Copy link
Contributor

I was poking around the repo and saw these few spots where I thought we could get some minor performance gains. There are also quite a few areas where we have multiple Seq.Filter's next to each other. I would also like to suggest updating those unless maintainers know of a reason why we have multiple filter iterations next to each other. Hope this helps!

Copy link
Collaborator

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I appreciate this PR, the proper thing to do here is most likely a bump of the analyzer tool and packages.
What you detected manually should be caught be a tool.

src/Common/StringParsing.fs Outdated Show resolved Hide resolved
|> Seq.filter (linkNotDefined doc)
|> Seq.map (getTypeLink ctx)
|> Seq.choose (fun line ->
if linkNotDefined doc line then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please invert the if/else here, I prefer the negative branch to be the if branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated to use a local variable to prevent a double negative. Let me know if you prefer to not use this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like updating the definition of linkNotDefined to linkDefined might also be an option. It is only used once and could probably ne simplified to a List.exist instead of the map/reduce combo.

src/FSharp.Formatting.Common/Templating.fs Outdated Show resolved Hide resolved
src/FSharp.Formatting.Common/Templating.fs Outdated Show resolved Hide resolved
@1eyewonder
Copy link
Contributor Author

Thanks for the quick review! I will go ahead and make these changes when I get back from travel early next week

@nojaf
Copy link
Collaborator

nojaf commented Jun 13, 2024

Thank you, safe travels!

@nojaf
Copy link
Collaborator

nojaf commented Jun 20, 2024

Here are the few areas I see consecutive Seq.filter/List.filter's used. Do you see any reason why we couldn't consolidate to help reduce iterations?

This codebase is rather old and has many authors. I don't believe there is a good reason these cases are not combined. Could you address these as well?

Copy link
Collaborator

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nojaf nojaf merged commit 2efb355 into fsprojects:main Jun 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants