Skip to content

Introduce more faster and memory optimal BitSet as replacment of Set<i32> #2361

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 7 commits into from
Jul 20, 2022

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Jul 4, 2022

Benchmark results for 1M items (JS):

BitSet add: 7.995ms
BitSet has: 4.894ms

Set<i32> add: 15.898ms
Set<i32> has: 15.414ms

Benchmark results for 100M items (Wasm):

BitSet add: 39.5000
BitSet has: 29.3000

Set<i32> add: 194.6000
Set<i32> has: 207.3000
  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@dcodeIO
Copy link
Member

dcodeIO commented Jul 6, 2022

What I'd find interesting in this context is a comparison of Set vs BitSet when compiled to Wasm. Mostly just curious, but perhaps the existing benchmark in JS can be extended? :)

@MaxGraey
Copy link
Member Author

MaxGraey commented Jul 6, 2022

Here AS bench BitSet vs Set:

playground

My results for Chrome for items 100M:

BitSet add: 39.5000
BitSet has: 29.3000

Set<i32> add: 194.6000
Set<i32> has: 207.3000

1M is too small for WebAssembly =)

@HerrCai0907
Copy link
Member

This algorithm use 1bit to store whether i32 number exists. What will happen if adding I32.MAX? It looks like will alloc 536870912(= 2 ** 32 / 8) bytes memory.

@MaxGraey
Copy link
Member Author

MaxGraey commented Jul 10, 2022

This algorithm use 1bit to store whether i32 number exists. What will happen if adding I32.MAX? It looks like will alloc 536870912(= 2 ** 32 / 8) bytes memory.

Yes, BitSet should be used for low-sparse scenarios. Where it is actually our case. The maximum number of locales per-function is 65536 for most Wasm engines. In fact, in real apps locale count does not exceed 50 per function (even after inlines). This will often be within backed buffer size

@MaxGraey MaxGraey merged commit 17e4647 into AssemblyScript:main Jul 20, 2022
@MaxGraey MaxGraey deleted the bitset branch July 20, 2022 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants