GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-153568: Reuse shared prefixes in generated parser rules by pablogsal · Pull Request #157465 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented Sep 13, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

For obj[index], the parser tries the attribute and call alternatives before the subscript one. Each choice starts by asking for the same obj again. The parse cache saves us from parsing it from scratch, but we still pay for another rule call and cache lookup.

This teaches the generator to keep that result and the position where it ended in local variables. When one choice fails, the next one can pick them up directly and try its own ending. It does this for adjacent choices that start with the same memoized rule, including expression, arithmetic and assignment-target rules.

The grammar stays as it is. The generator finds these shared starts on its own.

On my machine, this makes parsing the standard library and twenty repositories about 10.7% faster overall.

Codebase Python files Parsing speed
Standard library 2,054 11.5% faster
Django 2,932 11.7% faster
pandas 1,527 11.6% faster
NumPy 495 11.7% faster
SciPy 999 10.7% faster
scikit-learn 1,036 10.0% faster
SymPy 1,607 11.6% faster
Transformers 4,884 10.7% faster
PyTorch 4,890 10.5% faster
Home Assistant 18,731 11.1% faster
mypy 442 9.7% faster
Requests 37 11.3% faster
Flask 83 11.3% faster
FastAPI 1,138 10.6% faster
SQLAlchemy 673 11.3% faster
Black 345 9.4% faster
pytest 274 10.7% faster
Ansible 1,853 10.6% faster
Scrapy 491 11.9% faster
Celery 428 10.2% faster
Sphinx 774 10.6% faster

The table compares afe3d53d4d against main at fd0970c0ab, using release builds without PGO or LTO. Each result is the median of five paired runs. The timings include tokenization, building the AST and cleanup, without compiling bytecode or running the files.

This overlaps with #157437, which shares some of these starts by rewriting the grammar. Adding this on top of that PR still gives about 5.2% faster parsing across the standard library, mypy, Home Assistant and PyTorch in a separate run. That comparison does not include the rest of the pending parser changes.

Part of #153568.

  • Issue: Speed up the parser #153568

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pablogsal
pablogsal requested review from AA-Turner and lysnikolaou as code owners September 13, 2026 21:14
@bedevere-app bedevere-app Bot mentioned this pull request Sep 13, 2026
Speed up the parser #153568
Open
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 13, 2026
@pablogsal
pablogsal force-pushed the gh-153568-parser-prefix-cache branch from afe3d53 to 27f06b1 Compare September 14, 2026 20:03
@pablogsal
pythongh-153568: Reuse shared prefixes in generated parser rules
d0a0ce8
@pablogsal
pablogsal force-pushed the gh-153568-parser-prefix-cache branch from 27f06b1 to d0a0ce8 Compare September 14, 2026 20:50
@pablogsal
pablogsal merged commit 89fe985 into python:main Sep 15, 2026
63 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal deleted the gh-153568-parser-prefix-cache branch September 15, 2026 00:26
@bedevere-app bedevere-app Bot removed the awaiting core review label Sep 15, 2026
This was referenced Sep 15, 2026
gh-153568: Skip prefix tests when peg_generator is unavailable #157534
Merged
gh-153568: Factor shared prefixes in expression rules #157437
Closed
@python python deleted a comment from bedevere-bot Sep 15, 2026
@python python deleted a comment from bedevere-bot Sep 15, 2026
@bedevere-bot

bedevere-bot commented Sep 15, 2026

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 CentOS9 Refleaks 3.x (tier-1) has failed when building commit 89fe985.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/853/builds/4253) and take a look at the build logs.
  4. Check if the failure is related to this commit (89fe985) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/853/builds/4253

Summary of the results of the build (if available):

==

Click to see traceback logs
Note: switching to '89fe9857dd0832de9b597d63ecb11fa7a09984f1'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 89fe9857dd0 gh-153568: Reuse shared prefixes in generated parser rules (#157465)
Switched to and reset branch 'main'

make: *** [Makefile:2481: buildbottest] Error 3

Expanding reachable commits in commit graph: 99281
Expanding reachable commits in commit graph: 171162, done.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@pablogsal @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.