Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-157407: Reduce code size of ast and unicodeobject - #157393

Open
methane wants to merge 2 commits into
python:mainfrom
methane:reduce-codesize
Open

gh-157407: Reduce code size of ast and unicodeobject#157393
methane wants to merge 2 commits into
python:mainfrom
methane:reduce-codesize

Conversation

@methane

@methane methane commented Sep 13, 2026

Copy link
Copy Markdown
Member

This pull request refactors and optimizes the initialization and cleanup code for AST annotations and global static strings, focusing on reducing .text segment size.
This change reduces the size of Python's .text segment by approximately 1%, or about 60 KiB.

The main changes involve switching to offset-based iteration for both AST type cleanup and string initialization, and consolidating annotation logic to avoid code duplication.

Disclosure of the use of AI:

  • This change was selected and refined by me from a set of code-size reduction changes generated by Codex.
  • The description above was edited by me based on Copilot's "Generate Summary."
  • This text was translated into English by ChatGPT from the Japanese text I wrote.

@picnixz

picnixz commented Sep 13, 2026

Copy link
Copy Markdown
Member

Can you create an issue for such changes please? just for tracking purposes

@methane methane changed the title reduce .text size gh-157407: Reduce code size of ast and unicodeobject Sep 13, 2026
@methane

methane commented Sep 13, 2026

Copy link
Copy Markdown
Member Author

This pr reduces:

  • add_ast_annotations: 48K bytes
  • _PyAST_Fini : 13K bytes
  • _PyUnicode_InitGlobalObjects : 10K bytes

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.

2 participants