Repository navigation
Cache tok stream and JavaInput in Cleanups - #1532
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
Eliminates redundant full-file lexing across `Cleanups`, `CleanupPass`, `ImportOrderer`, and `Formatter.getFormatReplacements`: - Add a package-private `JavaInput(String, ImmutableList<Tok>)` constructor so `Cleanups` can cache `@Nullable ImmutableList<Tok> toks` and `@Nullable JavaInput javaInput` as separate lazy fields (invalidated alongside `parsed` in `applyReplacements`) without retaining `toks` on `JavaInput` for all callers. - Return `toks` and `javaInput` in `Cleanups.Result` so `AST_CLEANUPS` shares its full-file lex with `REORDER_MODIFIERS` and `SORT_IMPORTS`, and `Formatter` reuses `javaInput` directly or builds `new JavaInput(contents, toks)` when `--skip-reordering-modifiers` is set. - Update `CleanupsTest` to cover `toks`/`javaInput` reuse, `ImportOrderer` cached-`toks` reuse, adjacent unused-import + redundant-semicolon deletion, and `--fix-imports-only` not eagerly building `JavaInput`. Benchmarks (warm in-JVM `ThreadMXBean` CPU time): - `JavaInputAstVisitor.java` (140 KB, clean): med 178.1 -> 146.1 ms (1.22x), min 147.4 -> 105.2 ms (1.40x). PiperOrigin-RevId: 1025905856
copybara-service
Bot
force-pushed
the
test_1025905856
branch
from
November 25, 2026 17:44
67a4c8b to
a9f9908
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.
Cache tok stream and JavaInput in Cleanups
Eliminates redundant full-file lexing across
Cleanups,CleanupPass,ImportOrderer, andFormatter.getFormatReplacements:JavaInput(String, ImmutableList<Tok>)constructor soCleanupscan cache@Nullable ImmutableList<Tok> toksand@Nullable JavaInput javaInputas separate lazy fields (invalidated alongsideparsedin
applyReplacements) without retainingtoksonJavaInputfor allcallers.
toksandjavaInputinCleanups.ResultsoAST_CLEANUPSsharesits full-file lex with
REORDER_MODIFIERSandSORT_IMPORTS, andFormatterreusesjavaInputdirectly or buildsnew JavaInput(contents, toks)when--skip-reordering-modifiersis set.CleanupsTestto covertoks/javaInputreuse,ImportOrderercached-
toksreuse, adjacent unused-import + redundant-semicolon deletion,and
--fix-imports-onlynot eagerly buildingJavaInput.Benchmarks (warm in-JVM
ThreadMXBeanCPU time):JavaInputAstVisitor.java(140 KB, clean): med 178.1 -> 146.1 ms (1.22x),min 147.4 -> 105.2 ms (1.40x).