perf: Tokenizer no longer copies the source string - #647
Merged
Conversation
Tokenizer::new previously did src.to_string(), heap-allocating and copying the whole input on every parse call even though the tokenizer only ever reads through byte-range slices. The obvious fix (a &'a str field) and the fallback (Cow<'a, str>) both fail make check-mvl-limit (verified empirically: both trip "explicit lifetime is outside the qualified subset"), since tokenizer.rs is in the qualified subset that bans lifetimes beyond function-scoped elision. Instead, Tokenizer no longer stores the source at all: every method takes src: &str as a parameter, keeping every lifetime function-scoped and eliminating the copy entirely. spend: matched estimate (small)
iheitlager
force-pushed
the
perf/644-tokenizer-borrow-src
branch
from
August 29, 2026 17:26
4c1fc69 to
dc018bd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tokenizer::newdidsrc.to_string(), heap-allocating and copying the entire input on every parse call even though the tokenizer only ever reads through byte-range slices (self.src.get(...)).Tokenizer<'a> { src: &'a str }) nor the fallback (Cow<'a, str>) is viable: both tripmake check-mvl-limit("explicit lifetime is outside the qualified subset") sincesrc/parser/tokenizer.rsis in the qualified subset banning lifetimes beyond function-scoped elision.Tokenizerno longer stores the source at all — every scan method now takessrc: &stras a parameter, keeping every lifetime function-scoped (satisfying mvl-limit) while eliminating the per-parse copy entirely.Test plan
cargo test --lib— 959 passedcargo test --test tokenizer_proptest --test extracted_sql_corpus --test corpus --test tier1 --test unit_parser— all passedmake check-mvl-limit— passes (previously would have failed for both&'a strandCow<'a, str>alternatives, confirmed by direct experiment)cargo clippy --all-targets -- -D warnings— cleancargo fmt --checkcargo bench --bench compile_path— ran clean, no regressionsCloses #644
spend: matched estimate (small)
🤖 Analysis by Claude