Skip to content

Memoize blink fixer registry, precompile phpdoc regexes, parallelize rule tests - #185

Merged
TomasVotruba merged 2 commits into
mainfrom
blink-registry-regex-memo
Oct 9, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
blink-registry-regex-memo

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

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, and ByName scanned that list linearly. Config resolution calls ByName once per rule, so loading a dumped ECS config was roughly quadratic. The registry is now built once behind sync.Once into 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, ByName is a map lookup, and CanonicalOrder uses the prebuilt position index.

Precompile phpdoc tag regexes

PhpdocTagCasing.Fix and PhpdocInlineTagNormalizer.Fix compiled their regexes on every call, i.e. once per file. They now compile in WithConfig; the default (unconfigured) path uses a package-level precompiled set. Allocation count in BenchmarkFixPipeline is 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 in internal/fixer/rules to cut test wall-time. Verified green under -race.

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.
@TomasVotruba
TomasVotruba merged commit d7f1051 into main Oct 9, 2026
21 checks passed
@TomasVotruba
TomasVotruba deleted the blink-registry-regex-memo branch October 9, 2026 09:03
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.

1 participant