Extend performance group with list-length anti-pattern hints#1692
Open
mgajda wants to merge 1 commit intondmitchell:masterfrom
Open
Extend performance group with list-length anti-pattern hints#1692mgajda wants to merge 1 commit intondmitchell:masterfrom
mgajda wants to merge 1 commit intondmitchell:masterfrom
Conversation
Three opt-in warnings addressing lazy-list O(n) spine-forcing anti-patterns that are not covered by the existing default-group length/null hints: - `map f (reverse x)` -> `reverse (map f x)` extends the existing "Move reverse out" family (filter, mapMaybe, catMaybes, lefts, rights) to cover `map`, avoiding one intermediate cons spine. - `head (map f x)` -> `f (head x)` and `last (map f x)` -> `f (last x)` drop the fully-allocated mapped cons spine when only a single element is consumed. Enabled with `--with-group=performance`.
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 new opt-in warnings in the
performancegroup targeting lazy-listO(n) spine-forcing anti-patterns that are not covered by the existing
default-group length/null hints.
Summary
map f (reverse x)->reverse (map f x)-- extends the existing"Move reverse out" family (filter, mapMaybe, catMaybes, lefts,
rights) to cover
map, avoiding one intermediate cons spine.head (map f x)->f (head x)-- drops the fully-allocated mappedcons spine when only the first element is consumed.
last (map f x)->f (last x)-- same idea for the last element.The default group already covers
length x {==,>,>=,<,<=,/=} {0,1}andreverse (reverse x); these three hints address the remaining commonspine-forcing patterns.
Independence
This PR is intentionally independent of other in-flight
performancegroup proposals (STM-avoidance, strictness/roundtrip, IORef/State/
container folds). If one of those merges first, this branch simply
extends the existing
performancegroup rather than introducing it; ifit merges first, those branches extend the group introduced here. The
three rules added here do not overlap in name, LHS, or RHS with any
rule in those other branches.
Activation
Test plan
cabal buildsucceedshlint --testpasses (965 hints, up from 964)tests/flag-with-group-performance-length.testcovers all three rules; exact column ranges verified
--with-group=performance(opt-in)