Speed up intersphinx resolutions - #14628
Open
larsoner wants to merge 1 commit into
Open
Conversation
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.
Purpose
Follow-up to #14612 (similar in spirit, different target): speed up intersphinx missed-name resolution for
std:labelandstd:termby changing from anO(n)toO(1)operation.When an intersphinx lookup misses case-sensitively,
_resolve_reference_in_domain_by_targetfalls back to a linear scan that lowercases every key in the inventory for every miss, for every inventory. In the MNE-Python docs, which has about 30intersphinx_mappingentries, this scan ran ~54k times for ~170M key comparisons.This PR builds a lazily-populated
{name.lower(): [names]}index per inventory. Resolution order (first match in inventory insertion order) and the duplicate/multiple-match warnings are unchanged. The index is kept off the environment so it is never pickled.Takes MNE doc serial build time from 246s to 229s (time in the function drops from ~15s to < 1s).
References
None
AI Disclosure
Claude (Fable 5 and Opus 5) was used to profile the build, diagnose the problem, and write the fix and tests. I reviewed and validated the implementation.