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

Simplify fromDistinct{Asc,Desc}List for Set, Map #1029

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

meooow25
Copy link
Contributor

Uses only the Stack, making FromDistinctMonoState unnecessary. This implementation also allows for quick access to the last element, which may be used in fromAscListWith, mapKeysWith, etc.

Seems to be slightly faster. Benchmarks on GHC 9.6.3:

Before
Set
  fromDistinctAscList:         OK
    21.4 μs ± 1.3 μs, 224 KB allocated, 4.4 KB copied, 8.0 MB peak memory
  fromDistinctAscList:fusion:  OK
    21.0 μs ± 1.5 μs, 288 KB allocated, 7.6 KB copied, 8.0 MB peak memory
  fromDistinctDescList:        OK
    21.5 μs ± 840 ns, 224 KB allocated, 4.4 KB copied, 8.0 MB peak memory
  fromDistinctDescList:fusion: OK
    20.5 μs ± 1.4 μs, 288 KB allocated, 7.9 KB copied, 8.0 MB peak memory

Map
  fromDistinctAscList:         OK
    28.5 μs ± 2.8 μs, 271 KB allocated, 6.7 KB copied, 9.0 MB peak memory
  fromDistinctAscList:fusion:  OK
    23.8 μs ± 1.6 μs, 336 KB allocated,  10 KB copied, 9.0 MB peak memory
  fromDistinctDescList:        OK
    30.6 μs ± 2.8 μs, 271 KB allocated, 6.7 KB copied, 9.0 MB peak memory
  fromDistinctDescList:fusion: OK
    23.5 μs ± 702 ns, 336 KB allocated,  10 KB copied, 9.0 MB peak memory

After

Set
  fromDistinctAscList:         OK
    21.8 μs ± 1.4 μs, 223 KB allocated, 4.3 KB copied, 8.0 MB peak memory,       same as baseline
  fromDistinctAscList:fusion:  OK
    18.8 μs ± 1.4 μs, 288 KB allocated, 7.6 KB copied, 8.0 MB peak memory, 10% less than baseline
  fromDistinctDescList:        OK
    22.9 μs ± 1.7 μs, 223 KB allocated, 4.4 KB copied, 8.0 MB peak memory,       same as baseline
  fromDistinctDescList:fusion: OK
    18.8 μs ± 1.5 μs, 288 KB allocated, 8.0 KB copied, 8.0 MB peak memory,  8% less than baseline

Map
  fromDistinctAscList:         OK
    26.9 μs ± 1.8 μs, 272 KB allocated, 6.6 KB copied, 9.0 MB peak memory,       same as baseline
  fromDistinctAscList:fusion:  OK
    20.6 μs ± 1.5 μs, 336 KB allocated,  10 KB copied, 9.0 MB peak memory, 13% less than baseline
  fromDistinctDescList:        OK
    26.5 μs ± 1.4 μs, 272 KB allocated, 6.6 KB copied, 9.0 MB peak memory, 13% less than baseline
  fromDistinctDescList:fusion: OK
    20.7 μs ± 1.4 μs, 336 KB allocated,  10 KB copied, 9.0 MB peak memory, 11% less than baseline

Uses only the Stack, making FromDistinctMonoState unnecessary.
This implementation also allows for quick access to the last element,
which may be used in fromAscListWith, mapKeysWith, etc.
@meooow25 meooow25 force-pushed the fromDistinctAscList-simplify branch from e82e287 to ea7b5ad Compare August 25, 2024 07:50
@meooow25
Copy link
Contributor Author

This is a tweak to the implementation I added in #950, motivated by reasons mentioned above (simpler IMO, access to last element).
Don't think there is much to be discussed here, but let me know if you think otherwise @treeowl.

@meooow25 meooow25 merged commit 41005b5 into haskell:master Aug 31, 2024
11 checks passed
@meooow25 meooow25 deleted the fromDistinctAscList-simplify branch August 31, 2024 10:53
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