Repository navigation
Turbine: defer identifier interning and avoid String allocation for keywords. - #555
Merged
Merged
Conversation
…eywords. In `StreamLexer`: * Match keywords directly on the source `String` slice (`makeIdent(String, int, int)`) using a 2D `Token[][][] KEYWORDS` table bucketed by length and first character (`c0 - 'a'`) and `String.startsWith` rather than calling `internedString` for every identifier/keyword token. Because `Parser` skips method bodies and field initializers without calling `lexer.stringValue()`, most identifier tokens in a compilation unit never need a `String` instance allocated or interned. * Cache the lazily interned result in `value` inside `stringValue()` so repeated `stringValue()` calls for the same token do not re-query `StringCache`. On Chromium's `chrome_java` target (1,755 source files), running on the JVM (measuring this CL alone): * In-process `Parser.parse` across all 1,755 source files (15 timed iterations after 15 warmup iterations): mean CPU time decreases by 30.2 ± 8.8 ms (16.3%; 95% CI 11.6–21.1%), from 185.1 ± 13.0 ms to 154.9 ± 11.4 ms (median 176.3 ms to 145.2 ms, -17.7%). * End-to-end `chrome_java` wall time (`hyperfine --warmup 2 --runs 15`): decreases by 31.1 ± 28.3 ms (1.9%), from 1.67 s to 1.64 s with default JVM flags, and by 46.1 ± 41.2 ms (2.7%), from 1.71 s to 1.66 s with `-Xms4g -Xmx4g`. PiperOrigin-RevId: 1005354417
copybara-service
Bot
force-pushed
the
test_1004779192
branch
from
October 23, 2026 06:59
163eb88 to
7c3bd24
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.
Turbine: defer identifier interning and avoid String allocation for keywords.
In
StreamLexer:Stringslice (makeIdent(String, int, int)) using a 2DToken[][][] KEYWORDStable bucketed by length and first character (c0 - 'a') andString.startsWithrather than callinginternedStringfor every identifier/keyword token. BecauseParserskips method bodies and field initializers without callinglexer.stringValue(), most identifier tokens in a compilation unit never need aStringinstance allocated or interned.valueinsidestringValue()so repeatedstringValue()calls for the same token do not re-queryStringCache.On Chromium's
chrome_javatarget (1,755 source files), running on the JVM (measuring this CL alone):Parser.parseacross all 1,755 source files (15 timed iterations after 15 warmup iterations): mean CPU time decreases by 30.2 ± 8.8 ms (16.3%; 95% CI 11.6–21.1%), from 185.1 ± 13.0 ms to 154.9 ± 11.4 ms (median 176.3 ms to 145.2 ms, -17.7%).chrome_javawall time (hyperfine --warmup 2 --runs 15): decreases by 31.1 ± 28.3 ms (1.9%), from 1.67 s to 1.64 s with default JVM flags, and by 46.1 ± 41.2 ms (2.7%), from 1.71 s to 1.66 s with-Xms4g -Xmx4g.