Skip to content

sql-parser: Shrink AST nodes - #41117

Merged
def- merged 1 commit into
MaterializeInc:mainfrom
def-:perf/layout-parser
Nov 29, 2026
Merged

def- merged 1 commit into
MaterializeInc:mainfrom
def-:perf/layout-parser

Conversation

@def-

@def- def- commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Box the window spec in Function::over and the SHOW statement in SetExpr::Show. Both are large and rarely present, but increased the size of Expr and Statement. On x86-64 Expr: 240 -> 136 bytes, Statement: 1,736 -> 920 bytes.

parse_statements reserves exactly one slot before pushing the first statement. Most inputs contain a single statement, and each spare slot costs the size of a full statement. After parsing each statement, it immediately checks for a semicolon or the end of input, eliminating the delimiter flag.

When unwrapping (SHOW ...), the parser moves the SHOW node into the top-level Statement::Show, avoiding a clone.

This makes the parser allocate ~28% less memory, also happens to be slightly faster.

Box the window spec in `Function::over` and the SHOW statement in
`SetExpr::Show`. Both are large and rarely present, but they set the
size of every `Expr` and `Statement`. On x86-64, `Expr` shrinks from 240
to 136 bytes and `Statement` from 1,736 to 920 bytes, so every AST
allocation that holds one gets smaller.

`parse_statements` reserves a single slot for the first statement, since
most inputs contain one and each spare slot is a full statement.
Unwrapping `(SHOW ...)` into a top-level `Statement::Show` moves the
node instead of cloning it.

The parser allocates about 28% fewer bytes, and parsing and dropping
ASTs gets faster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@def- def- changed the title sql-parser: Cut parser allocation bytes by 28% on testdrive SQL sql-parser: Shrink AST nodes to reduce parser allocations Nov 28, 2026
@def-
def- force-pushed the perf/layout-parser branch from 77b7dd4 to 7de28ea Compare November 28, 2026 12:46
@def-
def- requested a review from ggevay November 28, 2026 12:54
@def- def- changed the title sql-parser: Shrink AST nodes to reduce parser allocations sql-parser: Shrink AST nodes Nov 28, 2026
@def-
def- marked this pull request as ready for review November 28, 2026 12:54
@def-
def- requested a review from a team as a code owner November 28, 2026 12:54

@ggevay ggevay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One minor thing: could the description also cover the changes besides the boxing? parse_statements now reserves one slot and has its end-of-statement check rewritten, and the (SHOW ...) unwrap moves the SHOW node instead of cloning it. The commit message mentions the reserve and the move, but the squash commit takes its message from the PR description.

@def-
def- merged commit 7f3b83d into MaterializeInc:main Nov 29, 2026
88 checks passed
@def-
def- deleted the perf/layout-parser branch November 29, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants