Open meooow25 opened 2 months ago
minViewSure/maxViewSure allocates one MinView/MaxView. This is avoidable, by not having the local go function.
minViewSure
maxViewSure
MinView
MaxView
go
https://github.com/haskell/containers/blob/c651094ec026b90c4e9d4ed81bc15eb337d3fc2e/containers/src/Data/Map/Internal.hs#L4017-L4024
Running map-benchmarks on minView (which uses minViewSure) and difference (which uses glue which uses minViewSure and maxViewSure):
map-benchmarks
minView
difference
glue
Name Time - - - - - - - - Allocated - - - - - A B % A B % difference 90 μs 78 μs -13% 351 KB 287 KB -18% minView 28 ns 22 ns -22% 167 B 135 B -19%
minViewSure
/maxViewSure
allocates oneMinView
/MaxView
. This is avoidable, by not having the localgo
function.Before
https://github.com/haskell/containers/blob/c651094ec026b90c4e9d4ed81bc15eb337d3fc2e/containers/src/Data/Map/Internal.hs#L4017-L4024
Core with GHC 9.6
``` Rec { -- RHS size: {terms: 38, types: 63, coercions: 0, joins: 0/0} $wgo6_rpA5 :: forall {k} {a}. k -> a -> Map k a -> Map k a -> (# k, a, Map k a #) [GblId[StrictWorker([!, ~, !, !])], Arity=4, Str=<1L>After
Core, again
``` Rec { -- RHS size: {terms: 38, types: 63, coercions: 0, joins: 0/0} Data.Map.Internal.$wminViewSure [InlPrag=[2], Occ=LoopBreaker] :: forall {k} {a}. k -> a -> Map k a -> Map k a -> (# k, a, Map k a #) [GblId[StrictWorker([!, ~, !, !])], Arity=4, Str=<1L>Benchmarks
Running
map-benchmarks
onminView
(which usesminViewSure
) anddifference
(which usesglue
which usesminViewSure
andmaxViewSure
):