Skip to content

gh-153568: Skip parser memo lookups that cannot match - #153571

Merged
pablogsal merged 1 commit into
python:mainfrom
pablogsal:gh-153568-memo-filter
Jul 18, 2026
Merged

pablogsal merged 1 commit into
python:mainfrom
pablogsal:gh-153568-memo-filter

Conversation

@pablogsal

@pablogsal pablogsal commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

Most memoization probes miss, and each one walked a linked list through arena memory to find out. A per-token filter of the memoized rule types answers definite misses with a single bit test.

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.82 s
this PR 1.72 s 1.06x faster
Each token now carries a small filter of the rule types present in its
memo list, so the common case of a miss no longer walks the list.
@pablogsal
pablogsal force-pushed the gh-153568-memo-filter branch from f6d8abf to a638dad Compare July 11, 2026 13:58
@brettcannon
brettcannon removed their request for review July 13, 2026 17:16
@pablogsal
pablogsal merged commit d49e76b into python:main Jul 18, 2026
50 checks passed
@pablogsal
pablogsal deleted the gh-153568-memo-filter branch July 18, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant