Skip to content
Hacker News front page

PostHog rewrote its SQL parser with AI, 70x faster

I rewrote PostHog's SQL parser, 70x faster, while barely looking at the code

PostHog engineer Robbie Coomber used multiple parallel Claude Code sessions to rewrite the company's SQL parser from ANTLR-generated C++ into 16K lines of hand-rolled Rust, achieving a ~70x speedup. The old parser relied on ANTLR's graph-walking interpreter; the new one uses recursive descent with a Pratt expression loop and backtracking only where needed. Development was driven by an oracle approach: the old parser's output served as ground truth, and the team iterated by finding disagreeing SQL, fixing the new parser, and re-running tests. The new parser matches the old one on all realistic queries, diverging only on deliberately pathological cases like SELECT SELECT FROM FROM WHERE WHERE AND AND. The post does not disclose specific latency numbers, hardware, or how the 70x figure was measured.

Why it matters: A PostHog engineer ran several parallel Claude Code sessions to rewrite an ANTLR-generated C++ SQL parser as 16,000 lines of hand-written Rust, about 70x faster, using recursive descent plus a Pratt loop.

Read the original ↗Export Markdown