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

perf(package): only try to read files that exist #3904

Merged
merged 4 commits into from
Apr 25, 2022

Conversation

andytom
Copy link
Member

@andytom andytom commented Apr 21, 2022

Description

Have refactored the package module to improve performance. Before this
change the module would try to open every single file that could contain
some package information until it found a valid version. This resulted
in a lot of unneeded disk IO. Have added a new fn, read_file_from_pwd
that uses the current context to check if that file already exists and
fast failing if it doesn't.

Motivation and Context

From my local testing this speeds up the package module from taking ~1ms to ~50µs in an empty directory.

Screenshots (if appropriate):

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

Checklist:

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

Have refactored the package module to improve performance. Before this
change the module would try to open every single file that could contain
some package information until it found a valid version. This resulted
in a lot of unneeded disk IO. Have added a new fn, `read_file_from_pwd`
that uses the current context to check if that file already exists and
fast failing if it doesn't. From my local testing this speeds up the
package module from taking ~1ms to ~50µs in an empty directory.
@andytom andytom requested a review from a team April 21, 2022 20:51
@andytom andytom marked this pull request as ready for review April 21, 2022 21:11
Copy link
Member

@davidkna davidkna left a comment

Choose a reason for hiding this comment

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

The changes themselves look good.

A few other files seem to have similar utils::read_file(context.current_dir.join("...")) calls, so this should perhaps also cover those.

src/utils.rs Outdated Show resolved Hide resolved
@andytom
Copy link
Member Author

andytom commented Apr 24, 2022

The changes themselves look good.

A few other files seem to have similar utils::read_file(context.current_dir.join("...")) calls, so this should perhaps also cover those.

The only one I found from a quick check was the haskell module, which I have updated, but maybe I missed something.

Edit scratch that just noticed can update the node module.

@davidkna
Copy link
Member

@andytom There's also the nodejs module has (base_dir is current_dir) and the terraform module (though it would be harder to replace there since it might read from a different location`).

@andytom andytom merged commit 2a650bf into starship:master Apr 25, 2022
@andytom andytom deleted the refactor/package_module branch April 25, 2022 14:18
@andytom
Copy link
Member Author

andytom commented Apr 25, 2022

Thanks for the review @davidkna

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.

None yet

2 participants