Visitar URL original
Shrink call keyword capacity by charliermarsh · Pull Request #26475 · astral-sh/ruff · GitHub
Skip to content

Shrink call keyword capacity - #26475

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

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

codspeed Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 6.39%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 148 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 (b739bc8) with main (4b24ed1)

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
@charliermarsh
charliermarsh force-pushed the charlie/reduce-ast-keyword-capacity branch from 7c1aec5 to b739bc8 Compare July 7, 2026 15:59
@astral-sh-bot

astral-sh-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
flake8 29.18MB 29.13MB -0.17% (50.62kB) ⬇️
trio 70.91MB 70.85MB -0.08% (59.25kB) ⬇️
sphinx 168.62MB 168.56MB -0.04% (66.00kB) ⬇️
prefect 453.46MB 453.39MB -0.01% (69.25kB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
parsed_module 9.88MB 9.83MB -0.50% (50.62kB) ⬇️

trio

Name Old New Diff Outcome
parsed_module 15.19MB 15.13MB -0.38% (59.25kB) ⬇️

sphinx

Name Old New Diff Outcome
parsed_module 18.52MB 18.46MB -0.35% (66.00kB) ⬇️

prefect

Name Old New Diff Outcome
parsed_module 19.50MB 19.43MB -0.35% (69.25kB) ⬇️

@astral-sh-bot

astral-sh-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

@astral-sh-bot

astral-sh-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser

Copy link
Copy Markdown
Member

Is this too hard for both of us ;)

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