Skip to content

Eagerly perform set insertions in nub{Ord,Int}#1229

Open
meooow25 wants to merge 1 commit into
haskell:masterfrom
meooow25:nubord-set-eager-insert
Open

Eagerly perform set insertions in nub{Ord,Int}#1229
meooow25 wants to merge 1 commit into
haskell:masterfrom
meooow25:nubord-set-eager-insert

Conversation

@meooow25

Copy link
Copy Markdown
Contributor

Currently we create thunks for at every step that get forced at the next step when we check for set membership. Here we change the insertions to be eager. This means doing a bit of work upfront that would otherwise be pushed to the next step but without the overhead of creating a thunk for it, which reduces a noticeable amount of allocations overall.

The go functions can also be marked as strict in the input set now.

Benchmarks on GHC 9.14 show a decrease in allocations of 8% on nubOrd.noFusion_distinct and nubOrd.strings_noFusion_distinct.


Name                                Time - - - - - - - -    Allocated - - - - -
                                         A       B     %         A       B     %
nubOrd.issue1202_distinct            46 μs   42 μs   -8%    672 KB  618 KB   -8%
nubOrd.issue1202_repeat             4.0 μs  3.9 μs   -2%     16 KB   16 KB   +0%
nubOrd.noFusion_distinct             44 μs   39 μs   -9%    633 KB  579 KB   -8%
nubOrd.noFusion_repeat              1.8 μs  1.3 μs  -28%    152 B    96 B   -36%
nubOrd.strings_noFusion_distinct    114 μs  112 μs   -1%    626 KB  572 KB   -8%
nubOrd.strings_noFusion_repeat      4.2 μs  4.0 μs   -4%    154 B    98 B   -36%

Currently we create thunks for <insert x s> at every step that get
forced at the next step when we check for set membership. Here we change
the insertions to be eager. This means doing a bit of work upfront that
would otherwise be pushed to the next step but without the overhead
of creating a thunk for it, which reduces a noticeable amount of
allocations overall.

The go functions can also be marked as strict in the input set now.

Benchmarks on GHC 9.14 show a decrease in allocations of 8% on
nubOrd.noFusion_distinct and nubOrd.strings_noFusion_distinct.
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