Skip to content

Prefer use of peek_token_ref over peek_token where valid#2225

Merged
iffyio merged 1 commit intoapache:mainfrom
alexander-beedie:perf-peek-token
Feb 20, 2026
Merged

Prefer use of peek_token_ref over peek_token where valid#2225
iffyio merged 1 commit intoapache:mainfrom
alexander-beedie:perf-peek-token

Conversation

@alexander-beedie
Copy link
Contributor

@alexander-beedie alexander-beedie commented Feb 20, 2026

Started looking at performance optimisation opportunities that don't require structural or API changes - have identified several, and will make a series of PRs that each cover one change, to keep things clean/focused and easy to review.

Hopefully there will be a nice cumulative impact 👍

Description

Where valid, the following updates have been made to avoid unnecessary clones, by preferring the "ref" variant of several core parsing functions:

  • peek_tokenpeek_token_ref (~200 updates)
  • expectedexpected_ref (~100 updates)

Results

Local testing with sqlparser_bench tests showed the following improvements:

┌──────────────────────────────┬───────────┬───────────┬────────┐
│ benchmark                    │ main      │ this pr   │ change │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ sqlparser::select            │ 2.704 µs  │ 2.667 µs  │ -0.9%  │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ sqlparser::with_select       │ 12.893 µs │ 12.642 µs │ -1.7%  │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ parse_large_statement        │ 4.449 ms  │ 4.310 ms  │ -3.1%  │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ select_100_columns           │ 68.14 µs  │ 66.42 µs  │ -3.4%  │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ select_100_qualified_columns │ 141.35 µs │ 138.80 µs │ -1.6%  │
└──────────────────────────────┴───────────┴───────────┴────────┘

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @alexander-beedie!

@iffyio iffyio added this pull request to the merge queue Feb 20, 2026
Merged via the queue into apache:main with commit bfd944c Feb 20, 2026
10 checks passed
@alexander-beedie alexander-beedie deleted the perf-peek-token branch February 20, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants