Extend performance group with strict IORef/State/container folds#1691
Open
mgajda wants to merge 3 commits intondmitchell:masterfrom
Open
Extend performance group with strict IORef/State/container folds#1691mgajda wants to merge 3 commits intondmitchell:masterfrom
mgajda wants to merge 3 commits intondmitchell:masterfrom
Conversation
New group (enabled: false) flags single-primitive uses of STM where a non-transactional primitive from IORef/MVar/Chan/QSem gives the same operation at a fraction of the cost: the transaction log, commit-time validation, and retry machinery are pure overhead when a transaction touches a single variable and needs no composition. Hints cover TVar, TMVar, TChan, TQueue, and TSem. Multi-variable transactions correctly do not match (no false positives on genuinely composable STM). Activate with `--with-group=performance`.
Three additional opt-in hints: - Data.List.foldl f z x -> Data.List.foldl' f z x - Data.List.scanl f z x -> Data.List.scanl' f z x - Data.Set.fromList (map f (Data.Set.toList s)) -> Data.Set.map f s Only the list-qualified forms of foldl/scanl are matched. Unqualified `foldl` in Prelude is Data.Foldable.foldl (Foldable-polymorphic), where the Data.List.foldl' rewrite would be ill-typed on non-list containers. The same safety is applied to scanl against future generalisations. Activated together with the STM hints via `--with-group=performance`.
Adds strict-variant rewrites for the remaining high-value targets in the
opt-in performance group. All matches use fully-qualified module names
so they only fire on the specific lazy variants users actually imported.
- Data.IORef.modifyIORef / atomicModifyIORef -> primed forms
- Control.Monad.State.modify -> modify'
- Data.{Map.Strict, Map.Lazy, Set, IntMap.Strict, IntMap.Lazy,
HashMap.Strict, HashMap.Lazy}.foldl -> foldl'
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.
Layered on top of #1691 (performance-strictness). Merge that one first —
this PR's diff will collapse to its own commit once it lands.
Adds strict-variant rewrites for the remaining high-value targets in
the opt-in
performancegroup. All matches use fully-qualified modulenames so they fire only on the specific lazy variants users imported
(no risk of hitting polymorphic/Foldable instances).
Rules added
Data.IORef.modifyIORef/atomicModifyIORef→ primed formsControl.Monad.State.modify→modify'Data.{Map.Strict, Map.Lazy, Set, IntMap.Strict, IntMap.Lazy, HashMap.Strict, HashMap.Lazy}.foldl→foldl'Tests
cabal buildhlint --test— 966 tests pass