Skip to content
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

Improve fromAscList and friends for Set and Map #1083

Merged
merged 3 commits into from
Jan 4, 2025

Conversation

meooow25
Copy link
Contributor

@meooow25 meooow25 commented Dec 29, 2024

Make fromAscList, fromAscListWith, fromAscListWithKey more efficient by removing the intermediate list and making them good consumers in list fusion.

Related: #950, #1042

Closes #1032


Benchmarks with GHC 9.10.1

Set:

Name                   Time - - - - - - - -    Allocated - - - - -
                            A       B     %         A       B     %
fromAscList             47 μs   19 μs  -59%    240 KB  176 KB  -26%
fromAscList:fusion      88 μs   12 μs  -85%    527 KB  192 KB  -63%
fromDescList            48 μs   19 μs  -61%    240 KB  176 KB  -26%
fromDescList:fusion     90 μs   46 μs  -49%    558 KB  559 KB   +0%

Map:

Name                          Time - - - - - - - -    Allocated - - - - -
                                   A       B     %         A       B     %
fromAscList                    49 μs   27 μs  -45%    481 KB  209 KB  -56%
fromAscList:fusion             71 μs   15 μs  -78%    926 KB  288 KB  -68%
fromAscListWithKey             57 μs   29 μs  -48%    592 KB  288 KB  -51%
fromAscListWithKey:fusion      86 μs   16 μs  -81%    1.0 MB  297 KB  -71%
fromDescList                   49 μs   25 μs  -48%    481 KB  209 KB  -56%
fromDescList:fusion            71 μs   46 μs  -35%    958 KB  607 KB  -36%
fromDescListWithKey            55 μs   29 μs  -48%    589 KB  288 KB  -51%
fromDescListWithKey:fusion     92 μs   52 μs  -44%    1.0 MB  688 KB  -35%

@meooow25 meooow25 mentioned this pull request Dec 29, 2024
9 tasks
* Make fromAscList, fromAscListWith, fromAscListWithKey, fromDescList,
  fromDescListWith, fromDescListWithKey more efficient by removing the
  intermediate list and making them good consumers in list fusion.
* Update Set's fromAscList and fromDescList to keep the last of
  duplicates. This makes it consistent with all other fromList functions
  on Set and Map.
* Update fromDistinct{Asc,Desc}List to take 1 arg for consistent
  inlining behavior.
@meooow25 meooow25 merged commit dfeed8b into haskell:master Jan 4, 2025
13 checks passed
@meooow25 meooow25 deleted the set-map-asclist branch January 4, 2025 13:09
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.

Set.fromAscList and Set.fromDescList keep the first of duplicates, inconsistent with other functions
1 participant