Files
ruff/crates/ruff_python_parser
Micha Reiser 1518f1d5fd Drop excess capacity from Suites during parsing (#25368)
## Summary

Shrink Suite vectors to drop the excess capacity during parsing. 

I excluded other nodes for now to get a better sense of the performance
and memory impact.

I'm a bit conflicted on this. This is a pretty huge memory improvement
for ty, but there are a few linter benchmarks that regress by 1-2%
because some vectors need to be copied to smaller allocations, which
hurts performance. For the linter and formatter, it's also not important
to shrink the vectors, because the AST is never stored for long. But
this is different for ty where we cache the AST.

I'm curious to hear what others think on this. I could also try to
reduce the places where we call `shrink_to_fit`, e.g., only for
statements?
2026-05-29 18:17:16 +00:00
..

Ruff Python Parser

Ruff's Python parser is a hand-written recursive descent parser which can parse Python source code into an Abstract Syntax Tree (AST). It also utilizes the Pratt parsing technique to parse expressions with different precedence.

Try out the parser in the playground.

Python version support

The parser supports the latest Python syntax, which is currently Python 3.12. It does not throw syntax errors if it encounters a syntax feature that is not supported by the target-version. This will be fixed in a future release (see https://github.com/astral-sh/ruff/issues/6591).

Contributing

Refer to the contributing guidelines to get started and GitHub issues with the parser label for issues that need help.