Skip to content

gh-153568: Cache repeated identifiers while parsing#153577

Open
pablogsal wants to merge 1 commit into
python:mainfrom
pablogsal:gh-153568-ident-cache
Open

gh-153568: Cache repeated identifiers while parsing#153577
pablogsal wants to merge 1 commit into
python:mainfrom
pablogsal:gh-153568-ident-cache

Conversation

@pablogsal

@pablogsal pablogsal commented Jul 11, 2026

Copy link
Copy Markdown
Member

Every occurrence of a name paid a UTF-8 decode, a hash and an intern lookup, even though identifiers repeat constantly in real code. A small per-parse table now reuses the interned name created the first time a given spelling is seen, and everything it stores lives in the parse arena so no lifetime management is needed.

Benchmark (parsing 8 of the largest stdlib files, 1.3 MB, 20 times per run with _PyParser_ASTFromString — parser only, no AST-to-Python conversion; pyperf, interleaved runs):

build time per run speedup
main 1.70 s ± 0.02
this PR 1.45 s ± 0.01 1.17x faster

Identifiers repeat constantly in real code, so the parser now reuses
the interned name created the first time it sees a given spelling.
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.

1 participant