HeadlinesBriefing favicon HeadlinesBriefing.com

ast-grep Rewrites Tree-sitter in Rust, 30% Faster

Hacker News •
×

ast-grep has rewritten the core of the Tree-sitter parser in Rust, achieving significant performance improvements. The new Rust core is faster at parsing, reading syntax trees, and within ast-grep itself. While the parser alone is 29.74% faster, the end-to-end ast-grep application sees a 22.2% reduction in user CPU time.

This rewrite focused on creating a narrower runtime optimized for AI coding agents that analyze complete file snapshots. While existing generated languages and parsers remain compatible, features like native Web Assembly loading and incremental old-tree reuse were removed. The Rust build also introduced a trade-off, using approximately 8 Mi B more memory compared to the C version.

The decision to rewrite stemmed from Tree-sitter being a performance bottleneck for ast-grep. Despite the complexities of the C implementation, the advent of AI-assisted coding tools made the ambitious undertaking feasible for a single developer. The process involved using Chat GPT to translate the C core into Rust, prioritizing behavioral parity with the original C implementation while gradually optimizing.