Repository navigation
Collapse single-element blink edit loops into one splice - #192
Merged
Merged
Conversation
Several fixers removed or inserted a contiguous run of tokens one element at a time via RemoveAt/InsertAt in a loop. Each call shifted the whole tail once, so a k-token span cost k tail moves, making those rules O(n^2) on large files where memmove dominated the profile. Replace the per-element loops with a single ReplaceRange or the new InsertSliceAt, so the tail shifts once per span. The edited token set is identical, so output is byte-for-byte unchanged. BenchmarkFixPipeline: 1class ~99.8us -> ~90.7us (-9%) 8classes ~636us -> ~600us (-6%) 64classes ~6.61ms -> ~6.12ms (-7%) 256classes ~49.3ms -> ~44.5ms (-10%)
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.
Why
After #187 made same-length
ReplaceRangean in-placeslices.Replace, profilingBenchmarkFixPipeline/256classesshowedmemmoveat ~47% of CPU. A chunk of that came from fixers that removed or inserted a contiguous run of tokens one element at a time, viaRemoveAt/InsertAtin a loop. Each call shifts the whole tail once, so editing a k-token span costs k tail moves - O(n^2) on large files.What
Replace those per-element loops with a single
ReplaceRange(removal) or the newStream.InsertSliceAt(insertion), so the tail shifts once per span instead of once per token. The set of edited tokens is identical, so output is byte-for-byte unchanged.Touched:
LongToShorthandOperator,StandardizeIncrement,IncrementStyle,AssignNullCoalescingToCoalesceEqual,EmptyLoopBody,convertLongArray, nullable-type removal, unused-import and alias removal, plus thecsbInsert/nasReplace/ modifier-reorder / operator-linebreak insert helpers.Benchmarks
go test -bench=BenchmarkFixPipeline -benchmem:No regression on the small-file path; the large cases improve.
Correctness
go test -race ./...passes;gofmt -l -s,go vet, modernize andgolangci-lintare clean.mainacross all four parity corpora - rector-src (1663 files), mautic (4553), laravel (3083), rector (1279), 0 differing files.