Repository navigation
Conversation
`Multidictionary` maintained a reverse index on every insertion, but only `removeOccurrences(of:)` needs it (and `keysContainingValue(_:)`, which only assertions and tests call). Reading the priors re-records every arc of the dependency graph, so maintaining the index was most of the time spent reading them: in a large app module, 3.5 of 4.2 CPU-s. Build the index on the first `removeOccurrences(of:)` and maintain it from then on. It's stored inline as an optional, so copies keep value semantics. Equality only compares the forward dictionary, which the index is derived from. Reading the priors of a generated 2,000-file module takes 0.43 s instead of 0.96 s. Resolves swiftlang#2259 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jshier
requested review from
DougGregor,
artemcm,
compnerd and
owenv
as code owners
November 9, 2026 02:15
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.
Resolves #2259.
Multidictionaryhas been updated to build the reverse index on the firstremoveOccurrences(of:)and maintain it from then on. It's stored inline as an optional, so copies keep value semantics. Its behavior is unchanged for every caller.Alternatively, the reverse index could be built on the first access of
keysContainingValuessince it's public API, but since that was only accessed in assertions, it would make debug builds pay the cost more often.Measured results:
In Xcode, this is on the critical path of every edit ("Planning Swift module" took 12.5 s in each one-line-edit build of the app).
Testing: the new
MultidictionaryTestscover lookups before the index exists, inserting and removing after it's built, and copies with and without it. Behavior is unchanged, so they also pass without the change. TheMultidictionaryTests,ModuleDependencyGraphTests,DependencyGraphSerializationTestsand incremental suites pass.