Skip to content

Shrink call keyword capacity#26475

Draft
charliermarsh wants to merge 3 commits into
mainfrom
charlie/reduce-ast-keyword-capacity
Draft

Shrink call keyword capacity#26475
charliermarsh wants to merge 3 commits into
mainfrom
charlie/reduce-ast-keyword-capacity

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 30, 2026

Copy link
Copy Markdown
Member

Summary

Collect call keywords in a Vec, then move them into an exactly sized ThinVec before retaining them in the AST. The ordinary conversion preserved the Vec's spare capacity, while constructing and shrinking a ThinVec directly added work to the hot parse loop. This keeps the original parsing path and performs one exact-capacity conversion at finalization.

This reduces retained AST memory from 956,062 bytes to 899,358 bytes (-5.93%) and full parsed memory from 1,208,698 bytes to 1,151,994 bytes on the existing five-file benchmark corpus. ty's normalized parsed_module memory also fell by 32,384 bytes across three identical runs.

The parser, AST, formatter, linter, and ruff_db test suites pass (4,254 tests), with no snapshot changes, and prek passes. This PR remains a draft while CodSpeed validates the revised construction strategy.

@MichaReiser

MichaReiser commented Jun 30, 2026

Copy link
Copy Markdown
Member

are you taking over my unfinished PRs (feel free to do so, I haven't found any combination that's nice perf wise)

#26227

@charliermarsh

Copy link
Copy Markdown
Member Author

No, I didn't see #26227

@codspeed-hq

codspeed-hq Bot commented Jun 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 6.39%

⚡ 1 improved benchmark
✅ 146 untouched benchmarks
⏩ 4 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory parser[large/dataset.py] 776.3 KB 729.7 KB +6.39%

Tip

Curious why this is faster? Use the CodSpeed MCP and ask your agent.


Comparing charlie/reduce-ast-keyword-capacity (7c1aec5) with main (e4945bd)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@MichaReiser

MichaReiser commented Jun 30, 2026

Copy link
Copy Markdown
Member

Noooo, please fix it for me 😆 I already have way too many draft PRs

@charliermarsh charliermarsh reopened this Jun 30, 2026
@charliermarsh

Copy link
Copy Markdown
Member Author

Haha ok

@charliermarsh charliermarsh added the performance Potential performance improvement label Jun 30, 2026
@charliermarsh charliermarsh force-pushed the charlie/reduce-ast-keyword-capacity branch from 460dd4c to 7c1aec5 Compare June 30, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Potential performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants