Skip to content

Turbine: defer identifier interning and avoid String allocation for keywords. - #555

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_1004779192
Oct 23, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
test_1004779192

Conversation

@copybara-service

Copy link
Copy Markdown

Turbine: defer identifier interning and avoid String allocation for keywords.

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.

…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
copybara-service Bot merged commit 7c3bd24 into main Oct 23, 2026
2 checks passed
@copybara-service
copybara-service Bot deleted the test_1004779192 branch October 23, 2026 06:59
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.

0 participants