lemire / FastBitSet.js

Speed-optimized BitSet implementation for modern browsers and JavaScript engines
Apache License 2.0
158 stars 19 forks source link

it is slow #16

Closed Yaffle closed 2 years ago

Yaffle commented 2 years ago

Hi, I am not using your library, but would like to ask if usage of 32 bit integers affects performance.

In my test of your library it is slower if I set every 30th or 31th bits:

var S = 4000;
var test = function (A) {
  var set = new FastBitSet();
  set.add(S);
  var set2 = new FastBitSet();
  for (var i = 0; i < S; i += 32) {
    set2.add(i + A);
  }
  console.time();
  for (var i = 0; i < S**2; i++) {
    set.change(set2);
  }
  console.timeEnd();
};
test(29);
test(30);

This script outputs something like: default: 2789.47802734375 ms default: 3693.5849609375 ms

On the page https://v8.dev/blog/pointer-compression it is said, that Chrome SMI is a 30 bit signed integer... May be this is why it is slower.

lemire commented 2 years ago

I understand that you believe it would be possible to significant boost the performance fo FastBitSet and you find it slow compared to your design.

I invite you to produce a pull request.

I am closing this particular issue. Let us discuss your ideas with actual code in hand.

Thanks again.

Yaffle commented 2 years ago

@lemire , I think the code change to switch to 31bit word size may affect performance of other operations, so you may not be happy with it. I have no plans to change your lib anyway, I am just trying to implement small BitSet with fast "change" ("xor").

Thanks for your reply.