Skip to content

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

Merged
meooow25 merged 1 commit into
haskell:masterfrom
meooow25:nubord-set-eager-insert
Jul 26, 2026
Merged

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

Conversation

@meooow25

@meooow25 meooow25 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

This results in an improvement in overall performance. See the added
Note [Eager set insertions] for an explanation.

Also mark the go functions as strict in the input set.

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%

This results in an improvement in overall performance. See the added
Note [Eager set insertions] for an explanation.

Also mark the go functions as strict in the input set.

Benchmarks on GHC 9.14 show a decrease in allocations of 8% on
nubOrd.noFusion_distinct and nubOrd.strings_noFusion_distinct.
@meooow25
meooow25 force-pushed the nubord-set-eager-insert branch from f7ccc96 to e46aa99 Compare July 26, 2026 22:57
@meooow25

meooow25 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Note for the record: The surprisingly large time improvement in nubOrd.noFusion_repeat compared to nubOrd.strings_noFusion_repeat is because, for some reason, this change convinces GHC to inline memberIndex only in nubOrd.noFusion_repeat.

I may look into this afterwards, but for now with this PR I just want to avoid the thunks.
It looks like -fworker-wrapper-cbv also helps with these benchmarks (#827).

@meooow25
meooow25 merged commit 6b32e8c into haskell:master Jul 26, 2026
19 checks passed
@meooow25
meooow25 deleted the nubord-set-eager-insert branch July 26, 2026 23:42
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