Skip to content

gh-153568: Use a managed dict for AST nodes - #160616

Open
lysnikolaou wants to merge 2 commits into
python:mainfrom
lysnikolaou:ast-node-inline-values
Open

lysnikolaou wants to merge 2 commits into
python:mainfrom
lysnikolaou:ast-node-inline-values

Conversation

@lysnikolaou

@lysnikolaou lysnikolaou commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

AST nodes had an explicit __dict__`` slot, so every node built by ast.parseallocated its own dict. WithPy_TPFLAGS_MANAGED_DICT`, node attributes are stored as inline values with shared keys instead.

ast.parse is ~15.8% faster, walking trees is ~15.9% faster, and the memory used by the AST trees is reduced by ~51.6%.

AST nodes had an explicit `__dict__`` slot, so every node built by
`ast.parse` allocated its own dict. With Py_TPFLAGS_MANAGED_DICT,
node attributes are stored as inline values with shared keys instead.

`ast.parse` is ~15.8% faster, walking trees is ~15.9% faster, and
the memory used by the AST trees is reduced by ~51.6%.
@bedevere-app bedevere-app Bot added awaiting core review type-feature A feature request or enhancement labels Oct 24, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 24, 2026

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fucking amazing!

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

Labels

awaiting merge type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants