Repository navigation
perf(python): Skip the Pragma Lookup in Files Without One - #23702
Conversation
EvidenceOn a large private monorepo (about 65.8k targets, 33.9k Python files), a cold
The output was identical to TestsThe existing parser tests (62 in Supporting detailsProfileA macOS A/BControl is
|
Every string literal that could be a string import candidate climbed the syntax tree with parent() and next_named_sibling() looking for a trailing `# pants: no-infer-dep` comment, which are linear in the number of siblings. About a third of the tree-sitter time in a cold peek of a large repo was spent there. A file that does not contain the pragma text cannot have one, so check once per file.
a34975d to
81323fc
Compare
What
For every string literal that could be a string import candidate, the Rust import parser (
ImportCollector::handle_string_candidate) looks for a trailing# pants: no-infer-depcomment by climbing the syntax tree withNode::parent()andNode::next_named_sibling(). In tree-sitter both are linear in the number of siblings, so a long module pays a lot for each string. The same lookup runs after every import statement and__import__call (is_pragma_ignored).A file that does not contain the text
# pants: no-infer-depcannot have such a comment. This checks that once per file, when the collector is created, and returns early from both lookups when the text is absent. The result is unchanged.Disclosure: investigated and implemented with claude.