[improvement](parser) Add case-insensitive stream fast paths - #67452
Draft
morrySnow wants to merge 3 commits into
Draft
[improvement](parser) Add case-insensitive stream fast paths#67452morrySnow wants to merge 3 commits into
morrySnow wants to merge 3 commits into
Conversation
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: Add a reference-based character stream and lexer differential test plus JMH coverage for stream creation, case-folding lookahead, tokenization, and end-to-end parsing. This freezes a shared harness before evaluating P4 implementations.
### Release note
None
### Check List (For Author)
- Test: Unit Test
- mvn -Pbenchmark -pl fe-sql-parser,fe-sql-parser-benchmark -Dmaven.build.cache.enabled=false package (170 tests passed)
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: CaseInsensitiveStream called Character.toUpperCase for every lexer lookahead. Fold ASCII lowercase characters with arithmetic while preserving the Character.toUpperCase fallback for all other code points. Exploratory JMH reduced prebuilt lowercase folding from 2.041 to 1.570 us/op and uppercase folding from 2.044 to 1.598 us/op.
### Release note
None
### Check List (For Author)
- Test: Unit Test
- mvn -pl fe-sql-parser -Dmaven.build.cache.enabled=false -Dtest=CaseInsensitiveStreamTest test
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: ANTLR copies every Java String into a code-point buffer before lexing. Read strings without surrogate code units directly while retaining the original ANTLR stream whenever code-point and UTF-16 indices differ. A 3-fork exploratory JMH run reduced identifier-heavy tokenization by 27.0%-28.2% and allocation by about 29%; short-query tokenization improved by 22.1%.
### Release note
None
### Check List (For Author)
- Test: Unit Test
- mvn -pl fe-sql-parser -Dmaven.build.cache.enabled=false -Dtest=CaseInsensitiveStreamTest test
- ./run-fe-ut.sh --run org.apache.doris.httpv2.websql.SingleStatementValidatorTest,org.apache.doris.nereids.parser.NereidsParserTest,org.apache.doris.nereids.parser.NereidsParserDigestTest (91 tests passed)
- Behavior changed: No
- Does this need documentation: No
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
Contributor
TPC-H: Total hot run time: 16942 ms |
Contributor
TPC-DS: Total hot run time: 81938 ms |
Contributor
ClickBench: Total hot run time: 14.52 s |
Contributor
FE Regression Coverage ReportIncrement line coverage |
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.
What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary:
Every SQL lexer currently copies its input through
CharStreams.fromString()and callsCharacter.toUpperCase()for every case-insensitive lookahead. This is visible in lexer allocation and identifier-heavy parsing time.Add two strictly compatible fast paths:
a-zwith arithmetic and retainCharacter.toUpperCase()for every other code point.getText, navigation, and errors remain unchanged.The public arbitrary-
CharStreamconstructor is preserved. All production String entry points now use the factory. ANTLR's nativecaseInsensitiveoption was evaluated but rejected because it changed existing Unicode behavior such as the handling ofſelect.Benchmark
Environment and method:
cf33a08bcd5, artifact SHA-25651700bef953361218912abc6aec348cecdec3fe61031eba10cc1ebc534bc91837aa7b5e6487, artifact SHA-2566e8edf78befc0dc349be398aae454c172b5cb968ee98d88a0e056d4c21a9c5d0-prof gcselect 1The isolated
createLexermeasurement for the surrogate-containing string/comment workload regresses by 5.9% because the compatibility guard scans for surrogates before falling back. The corresponding complete tokenize and parse paths improve by 3.6% and 10.8%; no end-to-end control workload regressed. Prebuilt lowercase character folding improves by 10.6%.The performance gains come from eliminating the copied input buffer for BMP-only SQL, avoiding its allocation, and replacing the common lowercase ASCII
Character.toUpperCase()call with an arithmetic branch.Correctness corpus:
69c811d0d80c52b40d8cd854e925ff4930aa6601c7d1e66541f2eb29f35db50a.noBackslashEscapesmodes); complete token tuple and lexer-error signatures match. SHA-256:66780d4e1d9224ea27c8f715ab33edd247faed1571030ba9e90a8ef3f6212180.Release note
None
Check List (For Author)
Tested with:
mvn -Pbenchmark -pl fe-sql-parser,fe-sql-parser-benchmark -Dmaven.build.cache.enabled=false clean package: 170 tests passed; Checkstyle passed../run-fe-ut.sh --run org.apache.doris.httpv2.websql.SingleStatementValidatorTest,org.apache.doris.nereids.parser.NereidsParserTest,org.apache.doris.nereids.parser.NereidsParserDigestTest: 91 tests passed.Token and parse corpus comparisons described above: no differences.
FE-only
./build.sh --fewith a fresh output directory: passed and producedSuccessfully build Doris.Full
./run-fe-ut.shwas attempted, but the host's Surefire JVM stopped during the pre-existingfe-connector-trinoTrinoPredicateConverterTestdynamic-attach path before reachingfe-core; it was terminated after 90 minutes with no P4-related failure.Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)