Skip to content

Comments

Optimise out string allocations and copies in keyword lookup#2226

Merged
iffyio merged 1 commit intoapache:mainfrom
alexander-beedie:optimise-keyword-lookup
Feb 23, 2026
Merged

Optimise out string allocations and copies in keyword lookup#2226
iffyio merged 1 commit intoapache:mainfrom
alexander-beedie:optimise-keyword-lookup

Conversation

@alexander-beedie
Copy link
Contributor

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

Follow-up to #2225.

Description

  • Found another ~25 or so places where we can make peek_tokenpeek_token_ref updates.

  • Profiling showed keyword lookups are a significant hotspot, so the following optimisations were made:

    • Added a Token::make_word_owned variant to avoid to_string() copies, factoring out the keyword lookup.
    • The keyword lookup itself was then optimised to eliminate to_ascii_uppercase() heap allocations.

Results

Ran sqlparser_bench several times with a fresh baseline to confirm the speedup 👍
These gains are in addition to the previous optimisation PR (baseline includes them).

┌──────────────────────────────┬───────────┬───────────┬────────┐
│ benchmark                    │ baseline  │ this pr   │ change │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ sqlparser::select            │ 2.691 µs  │ 2.477 µs  │ −8.0%  │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ sqlparser::with_select       │ 12.944 µs │ 11.652 µs │ −10.4% │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ parse_large_statement        │ 4.467 ms  │ 3.880 ms  │ −13.1% │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ format_large_statement       │ 242.62 µs │ 232.23 µs │ −4.1%  │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ select_100_columns           │ 68.56 µs  │ 63.94 µs  │ −6.7%  │
├──────────────────────────────┼───────────┼───────────┼────────┤
│ select_100_qualified_columns │ 142.47 µs │ 133.75 µs │ −6.1%  │
└──────────────────────────────┴───────────┴───────────┴────────┘

(Benchmarks were run on an Apple M3 Max)

@alexander-beedie alexander-beedie force-pushed the optimise-keyword-lookup branch 2 times, most recently from 831ebe2 to 0d8174c Compare February 20, 2026 20:22
@alexander-beedie alexander-beedie changed the title Avoid string allocations in keyword lookup Avoid string allocations and copies in keyword lookup Feb 20, 2026
@alexander-beedie alexander-beedie changed the title Avoid string allocations and copies in keyword lookup Optimise out string allocations and copies in keyword lookup Feb 21, 2026
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 23, 2026
Merged via the queue into apache:main with commit 36e8ce6 Feb 23, 2026
10 checks passed
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