Skip to content

Turbine: cache lexer strings in an array-backed StringCache - #551

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_1002773358
Oct 21, 2026
Merged

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

Conversation

@copybara-service

Copy link
Copy Markdown

Turbine: cache lexer strings in an array-backed StringCache

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.

`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
copybara-service Bot merged commit bd1f9a5 into main Oct 21, 2026
6 of 7 checks passed
@copybara-service
copybara-service Bot deleted the test_1002773358 branch October 21, 2026 21:53
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