Repository navigation
Speed up source ordering and annotation lookups with header modules. - #3267
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_1035115305
branch
from
December 4, 2026 16:48
9fda9a2 to
4bdca9a
Compare
With header modules, `rs_bindings_from_cc` is much slower on small targets: a namespace like `absl` or `std` has thousands of redeclarations (one for each copy of each header that reopens it), and two hot paths do work for each of them that doesn't depend on the declaration: * `IsBeforeInSourceOrder` builds a position key for both locations on every comparison by walking the include stack of the location within its module. The include stack only depends on the file, so it is now memoized per `FileID` (`SourceOrderCache::loaded_include_stacks`, which replaces `RepresentativeCopyCache` and also holds the representative copies). * `ImportDecl` looks up three annotations (`crubit_must_bind`, `crubit_pub_crate`, `crubit_do_not_bind`) for each redeclaration of a namespace, and each lookup visits all redeclarations: quadratic time. The lookups only read `AnnotateAttr`s, so they are now skipped for namespaces where no redeclaration has one (`NamespaceHasAnnotations`, memoized per canonical declaration and recomputed if the redeclaration chain grows). Neither change affects the output. PiperOrigin-RevId: 1036371973
copybara-service
Bot
force-pushed
the
test_1035115305
branch
from
December 4, 2026 17:00
4bdca9a to
abcd1e6
Compare
This branch was previously deployed
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.
Speed up source ordering and annotation lookups with header modules.
With header modules,
rs_bindings_from_ccis much slower on small targets: anamespace like
abslorstdhas thousands of redeclarations (one for eachcopy of each header that reopens it), and two hot paths do work for each of
them that doesn't depend on the declaration:
IsBeforeInSourceOrderbuilds a position key for both locations on everycomparison by walking the include stack of the location within its module.
The include stack only depends on the file, so it is now memoized per
FileID(SourceOrderCache::loaded_include_stacks, which replacesRepresentativeCopyCacheand also holds the representative copies).ImportDecllooks up three annotations (crubit_must_bind,crubit_pub_crate,crubit_do_not_bind) for each redeclaration of anamespace, and each lookup visits all redeclarations: quadratic time. The
lookups only read
AnnotateAttrs, so they are now skipped for namespaceswhere no redeclaration has one (
NamespaceHasAnnotations, memoized percanonical declaration and recomputed if the redeclaration chain grows).
Neither change affects the output.