Repository navigation
Turbine: cache lexer strings in an array-backed StringCache - #551
Merged
Merged
Conversation
`StringCache` is now a fixed-size, direct-mapped array instead of a `HashMap`. A string whose slot is taken by a different string replaces it, so canonicalization is best-effort, but lookups are cheaper and the cache doesn't retain every distinct string. Backing it with a `HashMap` or Guava's `CompactHashMap` instead was about 0.1 s slower with the default heap. `StreamLexer` now creates the strings for identifiers and other tokens read from the input through a `StringCache` per lexer, so repeated identifiers in a compilation unit share one instance. `StringCache` moves to a new `com.google.turbine.cache` package, so the parser doesn't depend on the binder. On Chromium's `chrome_java` target (about 1,750 source files), with Turbine built as a GraalVM native image, this reduces median wall time from 1.81 s to 1.41 s with the default heap, and from 0.63 s to 0.62 s with `-Xms4g`. The output is byte-for-byte identical. PiperOrigin-RevId: 1004252023
copybara-service
Bot
force-pushed
the
test_1002773358
branch
from
October 21, 2026 21:52
a7ada54 to
bd1f9a5
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: cache lexer strings in an array-backed StringCache
StringCacheis now a fixed-size, direct-mapped array instead of aHashMap. Astring whose slot is taken by a different string replaces it, so
canonicalization is best-effort, but lookups are cheaper and the cache doesn't
retain every distinct string. Backing it with a
HashMapor Guava'sCompactHashMapinstead was about 0.1 s slower with the default heap.StreamLexernow creates the strings for identifiers and other tokens read fromthe input through a
StringCacheper lexer, so repeated identifiers in acompilation unit share one instance.
StringCachemoves to a newcom.google.turbine.cachepackage, so the parser doesn't depend on the binder.On Chromium's
chrome_javatarget (about 1,750 source files), with Turbinebuilt as a GraalVM native image, this reduces median wall time from 1.81 s to
1.41 s with the default heap, and from 0.63 s to 0.62 s with
-Xms4g. Theoutput is byte-for-byte identical.