Various cargo-bazel performance improvements#3588
Merged
illicitonion merged 2 commits intobazelbuild:mainfrom Sep 4, 2025
Merged
Various cargo-bazel performance improvements#3588illicitonion merged 2 commits intobazelbuild:mainfrom
illicitonion merged 2 commits intobazelbuild:mainfrom
Conversation
dzbarsky
commented
Sep 2, 2025
dzbarsky
commented
Sep 2, 2025
| impl MetadataAnnotation { | ||
| pub(crate) fn new(metadata: CargoMetadata) -> MetadataAnnotation { | ||
| // UNWRAP: The workspace metadata should be written by a controlled process. This should not return a result | ||
| let workspace_metadata = find_workspace_metadata(&metadata).unwrap_or_default(); |
Contributor
Author
There was a problem hiding this comment.
this takes around 30ms in my repo, so let's just do it once and pass it down
dzbarsky
commented
Sep 2, 2025
dzbarsky
commented
Sep 2, 2025
| let workspace_metadata = find_workspace_metadata(metadata).unwrap_or_default(); | ||
| let workspace_members: HashSet<&PackageId> = metadata.workspace_members.iter().collect(); | ||
|
|
||
| // Determines whether or not a package is a workspace member. This follows |
Contributor
Author
There was a problem hiding this comment.
inlining this helper makes it obvious that we workspace_metadata should never be None here (and we definitely don't need to compute it repeatedly); also we convert workspace_members to a set for faster lookups
8fc3d1c to
fd337fd
Compare
dzbarsky
commented
Sep 3, 2025
| resolver_data: &TreeResolverMetadata, | ||
| tree_data: Option<&Select<BTreeSet<CrateId>>>, | ||
| ) -> Self { | ||
| // Build a dep tree mapping that's easily indexable via `cargo_metadata::PackageId` |
Contributor
Author
There was a problem hiding this comment.
hoist this to caller, this was accidentally quadratic
dzbarsky
commented
Sep 3, 2025
| let crates = resolve | ||
| .nodes | ||
| .iter() | ||
| .into_iter() |
Contributor
Author
There was a problem hiding this comment.
avoid cloning the nodes
fd337fd to
2a72251
Compare
illicitonion
approved these changes
Sep 4, 2025
Collaborator
illicitonion
left a comment
There was a problem hiding this comment.
All looks great, thanks so much!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is around 15-20% performance improvement on the entire module extension execution in my repo