Repository navigation
Cache JavaInput in Cleanups and fuse AST cleanup passes - #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 and parsing across `Cleanups`, `CleanupPass`, and `Formatter.getFormatReplacements`: - Retain `ImmutableList<Tok>` on `JavaInput` (`getToks()`), cache `JavaInput` in `Cleanups` (invalidated alongside `parsed` in `applyReplacements`), and return it in `Cleanups.Result` so `CleanupScanner`, `ImportOrderer` (when `javaInput` is already cached), `ModifierOrderer`, and `Formatter.getFormatReplacements` share a single full-file lex instead of 3 full-file lexes + 1 prefix lex on clean files. - Fuse `REMOVE_UNUSED_IMPORTS` and `AST_CLEANUPS` onto a single shared `JCCompilationUnit` parse (`applyFusedAstPasses`), passing `preExistingDeletions` into `CleanupScanner` so adjacent deletions (such as `import java.util.List;;`) remain identical. - Order `SORT_IMPORTS` before `REORDER_MODIFIERS` in `CleanupPass` so when imports are sorted (invalidating `javaInput`), `SORT_IMPORTS` only does a prefix lex (`CLASS_START`) and `REORDER_MODIFIERS` then builds `JavaInput` once for `Formatter` to reuse. - Update `CleanupsTest` to cover fused AST pass behavior, `javaInput` reuse, and adjacent unused-import + redundant-semicolon deletion. 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
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 JavaInput in Cleanups and fuse AST cleanup passes
Eliminates redundant full-file lexing and parsing across
Cleanups,CleanupPass, andFormatter.getFormatReplacements:ImmutableList<Tok>onJavaInput(getToks()), cacheJavaInputinCleanups(invalidated alongsideparsedinapplyReplacements), and returnit in
Cleanups.ResultsoCleanupScanner,ImportOrderer(whenjavaInputis already cached),
ModifierOrderer, andFormatter.getFormatReplacementsshare a single full-file lex instead of 3 full-file lexes + 1 prefix lex on
clean files.
REMOVE_UNUSED_IMPORTSandAST_CLEANUPSonto a single sharedJCCompilationUnitparse (applyFusedAstPasses), passingpreExistingDeletionsintoCleanupScannerso adjacent deletions (such asimport java.util.List;;) remain identical.SORT_IMPORTSbeforeREORDER_MODIFIERSinCleanupPassso whenimports are sorted (invalidating
javaInput),SORT_IMPORTSonly does aprefix lex (
CLASS_START) andREORDER_MODIFIERSthen buildsJavaInputonce for
Formatterto reuse.CleanupsTestto cover fused AST pass behavior,javaInputreuse, andadjacent unused-import + redundant-semicolon deletion.
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).