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

Add Data.IntSet.fromRange #965

Merged
merged 1 commit into from
Sep 27, 2023
Merged

Conversation

meooow25
Copy link
Contributor

@meooow25 meooow25 commented Jul 18, 2023

For #632

Benchmark on GHC 9.2.5:

  fromRange:       OK (0.20s)
    376  ns ±  22 ns, 4.0 KB allocated,   2 B  copied, 7.0 MB peak memory
  fromRange:small: OK (0.18s)
    10.0 ns ± 872 ps, 119 B  allocated,   0 B  copied, 7.0 MB peak memory

Comparing fromDistinctAscList [1..2^12] from #951 against fromRange (1,2^12), currently it takes 24.3 μs (~62x the time) and with fusion it would still take 4.49 μs (~11x the time).

fromRange (l,h) is faster than fromRange [l..h], primarily because we
can pack Tips with multiple elements at once.
@meooow25 meooow25 marked this pull request as ready for review July 28, 2023 21:27
@meooow25
Copy link
Contributor Author

meooow25 commented Jul 28, 2023

Note: I've made some changes to the algorithm. If you didn't see the previous version you can ignore this comment. I made the change because I realized that we could be forced to do $O(W)$ work even when $n$ is very small, making the complexity $O(n/W + W)$. I changed goL and goR to avoid this, so it's correctly $O(n/W)$ now. This can be observed on fromRange (-1,0) which changed from ~70ns to 10ns. Also fixed a bug where I used bitmapOfSuffix instead of bitmapOf, the tests ran fine because on x86 the shift value is masked to 5/6 bits anyway.

@treeowl
Copy link
Contributor

treeowl commented Sep 27, 2023

Cool!

@treeowl treeowl merged commit 9d395e4 into haskell:master Sep 27, 2023
9 checks passed
@meooow25 meooow25 deleted the intset-from-range branch October 1, 2023 09:36
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.

None yet

3 participants