Skip to content

Improve fromList for IntSet and IntMap #1137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 24, 2025

Conversation

meooow25
Copy link
Contributor

Implement a fusion-friendly version of the smarter algorithm proposed in #653.

For #1128.


Benchmarks on GHC 9.10.1:

IntSet:

Name                          Time - - - - - - - -    Allocated - - - - -
                                   A       B     %         A       B     %
fromList:asc                   46 μs   18 μs  -60%    480 KB  5.5 KB  -98%
fromList:asc:fusion            39 μs  4.1 μs  -89%    480 KB  5.5 KB  -98%
fromList:asc:sparse            95 μs   47 μs  -50%    864 KB  352 KB  -59%
fromList:asc:sparse:fusion     87 μs   41 μs  -52%    864 KB  352 KB  -59%
fromList:random               459 μs  467 μs   +1%    1.5 MB  2.4 MB  +67%
fromList:random:fusion        450 μs  459 μs   +1%    1.5 MB  2.4 MB  +67%
fromList:randomDups            57 μs   48 μs  -16%    352 KB  300 KB  -14%
fromList:randomDups:fusion     52 μs   48 μs   -7%    352 KB  300 KB  -14%
fromList:worstCase            711 μs  824 μs  +15%    6.9 MB   14 MB  +96%

IntMap:

Name                              Time - - - - - - - -    Allocated - - - - -
                                       A       B     %         A       B     %
fromList:asc                      100 μs   48 μs  -52%    864 KB  352 KB  -59%
fromList:asc:fusion                88 μs   37 μs  -57%    864 KB  352 KB  -59%
fromList:random                   480 μs  463 μs   -3%    1.5 MB  2.4 MB  +67%
fromList:random:fusion            452 μs  448 μs   +0%    1.5 MB  2.4 MB  +67%
fromList:randomDups               309 μs  263 μs  -15%    1.1 MB  1.7 MB  +57%
fromList:randomDups:fusion        296 μs  247 μs  -16%    1.1 MB  1.7 MB  +57%
fromList:worstCase                982 μs  1.1 ms  +16%    7.3 MB   14 MB  +97%
fromListWith:randomDups           316 μs  302 μs   -4%    1.3 MB  1.9 MB  +54%
fromListWith:randomDups:fusion    321 μs  335 μs   +4%    1.3 MB  2.3 MB  +86%

Implement a fusion-friendly version of the smarter algorithm proposed
in haskell#653.
@meooow25
Copy link
Contributor Author

meooow25 commented May 8, 2025

The worse performance of fromListWith:randomDups:fusion compared to fromListWith:randomDups is due to a fusion issue: GHC #25259. This previously showed up in #1042 too. Since we have a potential fix, i.e. defining our old foldl', we can avoid the problem, but I think it's better to just get this fixed in base.

@meooow25
Copy link
Contributor Author

I'm working on getting this fixed in base, but making moveToB NOINLINE also seems to do the trick, making the function small enough to not run into GHC #25259. This is good anyway because we are reducing the amount of code we inline.

@meooow25 meooow25 merged commit d1a4776 into haskell:master May 24, 2025
13 checks passed
@meooow25 meooow25 deleted the intmap-fromlist branch May 24, 2025 11:49
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