Giter Site home page Giter Site logo

Comments (3)

infusion avatar infusion commented on May 24, 2024

Hi
currently you can't control that behavior, since the library is optimized for speed, not memory. The 10 elements are a reasonable pre-allocation at the beginning to save re-allocations in most basic usecases < 320 bit. Especially when you narrow it down the way you're asking for you can't handle big jumps properly, such as .set(2), .set(1000). In your desired way you would increase the size linearly, instead of pre-allocating larger ranges.
Do you have a use case where 3*4 byte really make such a difference?

from bitset.js.

markg85 avatar markg85 commented on May 24, 2024

Hi,

Personally i'd argue that using a bitset most often implies one is going for memory efficiency above performance.

I do have a usecase where this really matters though it's very much niche.
I'm just playing with a site to show crypto prices. I'm using the crypto.com ticker API for that which gives me that number of 214 (that many different cryptos). In my specific case i get enough data from the ticker to send an update to the browser every .05 seconds. I'm already limiting the data i send a lot to the bare minimum but that's still a list of 214 entries with the difference between the previous message.

This brings down data usage per 0.5 seconds to ~300 bytes.

Now if i have a bitset that tells me which entries changed then i only need to send:

  • that bitset (ideally 216 bits, 27 bytes)
  • each changed value (that's 20 at most in this interval thus at most 80 bytes where i assume each entry is a 4 byte float)
  • new likely max packet size ~100 bytes per 0.5 seconds

So yeah, this very niche case, does in fact save quite a bit of data if it were possible with BitSet.

from bitset.js.

markg85 avatar markg85 commented on May 24, 2024

So, a very quick experiment with https://github.com/Callidon/bloom-filters/blob/master/src/bloom/bit-set.ts (from the bloom-filters package, the bitset is just for internal purposes).

That is memory efficient and it does in fact turn out that using such a structure gives me 0.5 second data blobs between 40-100 bytes. The API of that class is weird though... Oh well, works for my needs.

Could you perhaps consider adding a settable flag to your class to choose between memory efficiency and performance?

from bitset.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.