Repository navigation
Memoize blink fixer registry, precompile phpdoc regexes, parallelize rule tests - #185
Merged
Merged
Conversation
rules.All() rebuilt and re-sorted the full fixer list on every call, and ByName scanned it linearly - so config resolution, which calls ByName per rule, was quadratic. Build the sorted list and a name index once via sync.Once; All() returns a clone so callers may still append or reorder. PhpdocTagCasing and PhpdocInlineTagNormalizer recompiled their regexes on every Fix (once per file). Compile them in WithConfig instead.
The rule fixers are pure stateless value types over independent token streams, so their tests have no shared state. Mark each with t.Parallel() to cut test wall-time.
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.
Three Go-idiom improvements from a codebase audit. No behavior change; all existing tests pass under
-race.Build the fixer registry once
rules.All()rebuilt and re-sorted the entire fixer list on every call, andByNamescanned that list linearly. Config resolution callsByNameonce per rule, so loading a dumped ECS config was roughly quadratic. The registry is now built once behindsync.Onceinto a canonical-order slice plus a name index;All()returns a clone so callers that append or reorder (e.g. the set builders) stay correct,ByNameis a map lookup, andCanonicalOrderuses the prebuilt position index.Precompile phpdoc tag regexes
PhpdocTagCasing.FixandPhpdocInlineTagNormalizer.Fixcompiled their regexes on every call, i.e. once per file. They now compile inWithConfig; the default (unconfigured) path uses a package-level precompiled set. Allocation count inBenchmarkFixPipelineis unchanged for the default path and the per-file compile is gone for configured tag lists.Parallelize rule tests
The rule fixers are pure stateless value types operating on independent token streams, with no shared state, env or filesystem use. Added
t.Parallel()to the 333 top-level tests ininternal/fixer/rulesto cut test wall-time. Verified green under-race.