[rush] Optimize the execution speed of Rush#5007
[rush] Optimize the execution speed of Rush#5007octogonz merged 9 commits intomicrosoft:mainfrom L-Qun:main
Conversation
|
Conceptually this seems fine, but I'd want to do a lot of stress testing and verify the interaction with, e.g. the The other problem, though, is that the raw response of this call is potentially consumed by plugins that make use of the I'm reasonably confident that the performance impact of filtering |
The main time consumption comes from git ls-tree based on my local testing:
|
|
During my typical testing: The issue is that the call to I'd love to be able to reduce the scope, but it would be a breaking change, because we expose the full list of tracked files and their hashes here: |
Yes, It would be a breaking change. I modified this comments. |
|
Hi @dmichon-msft, I hope you're doing well! Just checking in to see if there’s anything I can clarify or update in this PR to move it forward |
| * The raw hashes of all tracked files in the repository. | ||
| * The raw hashes of the files relevant to the projects we care about are stored. | ||
| * (e.g. when running `rush build`, the hashes of all tracked files in the repository are stored) | ||
| * (e.g. when running `rush build --only`, only the hashes of files under the specified project are stored) |
There was a problem hiding this comment.
This won't work. Computation of operation hashes depends on the entire tree of their dependencies, whether or not you are currently executing said dependencies. So at minimum we always need the expansion of --to, not just the values passed to --only to be able to determine build cache entry ids.
There was a problem hiding this comment.
I see. I just want to express that we are no longer storing all the hashes. I’ve removed that description.
| const lookupByPath: IReadonlyLookupByPath<RushConfigurationProject> = | ||
| this._rushConfiguration.getProjectLookupForRoot(rootDirectory); | ||
|
|
||
| const filterPath: string[] = Array.from(projectSelection ?? []).map((project) => project.projectFolder); |
There was a problem hiding this comment.
At minimum the choice to perform filtering needs to be behind a flag in experiments.json, because it will break things for consumers with custom plugins, and needs to be a choice whether or not to apply such logic.
There was a problem hiding this comment.
I added a configuration to determine whether to enable this feature.
There was a problem hiding this comment.
Hi @dmichon-msft, I've addressed the comments and made the updates. When you get a chance, could you please take another look? Thanks!
dmichon-msft
left a comment
There was a problem hiding this comment.
Few minor things but otherwise looks good.
common/changes/@rushstack/package-deps-hash/main_2024-11-18-08-13.json
Outdated
Show resolved
Hide resolved
…-13.json Co-authored-by: David Michon <dmichon@microsoft.com>
Co-authored-by: David Michon <dmichon@microsoft.com>
Co-authored-by: David Michon <dmichon@microsoft.com>
Co-authored-by: David Michon <dmichon@microsoft.com>
| projectSelection && | ||
| this._rushConfiguration.experimentsConfiguration.configuration.enableSubpathScan | ||
| ) { | ||
| filterPath = Array.from(projectSelection).map(({ projectFolder }) => projectFolder); |
There was a problem hiding this comment.
For a followup PR: this feature will 100% break the build cache unless we update this to Array.from(Selection.expandAllDependencies(projectSelection), ({ projectFolder }) => projectFolder);
File hashes for dependencies are absolutely necessary when calculating build cache entry ids, unless the only selected phases don't depend on upstream projects at all.
There was a problem hiding this comment.
I suppose projectSelection already includes all the projects that need to be built?
There was a problem hiding this comment.
With --to, projectSelection includes all the dependencies; with --only, it does not. This was addressed by #5045 by expanding the project selection when invoking ProjectChangeAnalyzer.
There was a problem hiding this comment.
https://developer.microsoft.com/json-schemas/rush/v5/experiments.schema.json
@octogonz Could you help deploy a new schema endpoint that includes the enableSubpathScan field?

Summary
Recently, I noticed that when running Rush commands, Rush itself takes a considerable amount of time, even if I’m only building a single project.
After reviewing the Rush source code, I discovered that the cause of this issue is the execution of Git commands.
However, I suppose that we only need to retrieve the hash of the relevant project rather than all projects in the monorepo. So I made small changes for Rush, which can save over 50% of Rush's own execution time
How it was tested
Run the command
rush build --to @microsoft/rush. You will notice the time has improved:Before:
After:
Meanwhile, does not affect the cache hits of the built packages.
Impacted documentation
None.