Skip to content

Various cargo-bazel performance improvements#3588

Merged
illicitonion merged 2 commits intobazelbuild:mainfrom
hermeticbuild:zbarsky/perf-fixes
Sep 4, 2025
Merged

Various cargo-bazel performance improvements#3588
illicitonion merged 2 commits intobazelbuild:mainfrom
hermeticbuild:zbarsky/perf-fixes

Conversation

@dzbarsky
Copy link
Copy Markdown
Contributor

@dzbarsky dzbarsky commented Sep 2, 2025

This is around 15-20% performance improvement on the entire module extension execution in my repo

Comment thread crate_universe/src/metadata/cargo_tree_resolver.rs Outdated
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();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this takes around 30ms in my repo, so let's just do it once and pass it down

Comment thread crate_universe/src/metadata/metadata_annotation.rs Outdated
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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@dzbarsky dzbarsky force-pushed the zbarsky/perf-fixes branch 7 times, most recently from 8fc3d1c to fd337fd Compare September 3, 2025 20:26
resolver_data: &TreeResolverMetadata,
tree_data: Option<&Select<BTreeSet<CrateId>>>,
) -> Self {
// Build a dep tree mapping that's easily indexable via `cargo_metadata::PackageId`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hoist this to caller, this was accidentally quadratic

let crates = resolve
.nodes
.iter()
.into_iter()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

avoid cloning the nodes

Copy link
Copy Markdown
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

All looks great, thanks so much!

@illicitonion illicitonion added this pull request to the merge queue Sep 4, 2025
Merged via the queue into bazelbuild:main with commit 6d532fd Sep 4, 2025
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