perf: memoize erb_nodes and tag_nodes in ProcessedSource#455
Open
ryanquanz wants to merge 1 commit into
Open
Conversation
Add memoized erb_nodes and tag_nodes methods to ProcessedSource so that multiple linters share a single AST traversal per file instead of each traversing independently. Update all linters to use the memoized methods.
f6c3ce5 to
d19ef1d
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.
Summary
Add memoized
erb_nodesandtag_nodesmethods toProcessedSourceso that multiple linters share a single AST traversal per file instead of each traversing independently. Update all linters to use the memoized methods.Problem
Every linter that processes ERB or HTML tags calls
ast.descendants(:erb)orparser.nodes_with_type(:tag)independently. With 15+ linters enabled, the same AST is traversed 10+ times per file.Impact
The improvement is modest in isolation (~1–11% depending on workload), but compounds with other linter-level optimizations and eliminates redundant work across all linters.
Changes
15 files changed, +81 −23.
erb_nodesandtag_nodesmemoized methods toProcessedSources/ast.descendants(:erb)/erb_nodes/replacementsRequireInputAutocompleteandRequireScriptNoncechange from receivingparsertoprocessed_source(internal only)processed_source_spec.rbverifying memoization (object identity) and correctness (equivalence with non-memoized traversal)