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

Implement caching for dependency expansion #10887

Merged
merged 1 commit into from Mar 22, 2021

Conversation

Bo98
Copy link
Member

@Bo98 Bo98 commented Mar 19, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

This adds opt-in caching to Dependency.expand and Requirement.expand.

This massively increases the speed of those functions, if a cache key is passed. I've adjusted Formula#rescursive_dependencies and Formula#recursive_requirements to do this if no block is passed.

This massively improves the brew uses runtime from ~40s on Linux to about 6s, with most of that remaining time now being the actual Formula.to_a file loading.

Care is needed when choosing a cache key - the block is not re-evaulated on cache hits and so the cache key should be constructed depending on what variables might require rerunning the block.

I tried to be careful to clear the cache where it might be necessary - hopefully I haven't missed an edge case.

If successful, this should also speed up the test default formula (Linux) CI step.

@BrewTestBot
Copy link
Member

Review period will end on 2021-03-22 at 03:31:58 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 19, 2021
@Bo98 Bo98 force-pushed the dep-expand-caching branch 2 times, most recently from 0d4589c to dcfa634 Compare March 19, 2021 04:29
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Makes sense, nice work! The only thing I'd be tempted to do here is make the interface a bit more similar to the existing uses caching i.e. Formulary.enable_factory_cache! or something similar/shared which allows the cache keys to be set inside the relevant methods.

Library/Homebrew/formula.rb Outdated Show resolved Hide resolved
@Bo98
Copy link
Member Author

Bo98 commented Mar 19, 2021

something similar/shared which allows the cache keys to be set inside the relevant methods.

The hard bit is that the return value of Dependency.expand depends on the block passed, which varies from caller to caller.

@Bo98
Copy link
Member Author

Bo98 commented Mar 19, 2021

If successful, this should also speed up the test default formula (Linux) CI step.

About 12 minutes -> less than 2 minutes

@MikeMcQuaid
Copy link
Member

About 12 minutes -> less than 2 minutes

🤯

The hard bit is that the return value of Dependency.expand depends on the block passed, which varies from caller to caller.

Ah, I see. No worries, then.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 22, 2021
@BrewTestBot
Copy link
Member

Review period ended.

@Bo98 Bo98 merged commit ca33b3d into Homebrew:master Mar 22, 2021
@Bo98 Bo98 deleted the dep-expand-caching branch March 22, 2021 14:13
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 22, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants