Skip to content

Speed up intersphinx resolutions - #14628

Open
larsoner wants to merge 1 commit into
sphinx-doc:masterfrom
larsoner:intersphinx-ci-index
Open

Speed up intersphinx resolutions#14628
larsoner wants to merge 1 commit into
sphinx-doc:masterfrom
larsoner:intersphinx-ci-index

Conversation

@larsoner

Copy link
Copy Markdown
Contributor

Purpose

Follow-up to #14612 (similar in spirit, different target): speed up intersphinx missed-name resolution for std:label and std:term by changing from an O(n) to O(1) operation.

When an intersphinx lookup misses case-sensitively, _resolve_reference_in_domain_by_target falls 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 30 intersphinx_mapping entries, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants