Comments (3)
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.
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.
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)
- If the data is completely zero, then count leading zeros and count trailing zeros should return the word size HOT 9
- Why is isEmpty false even when all bits are set to 0? HOT 3
- New Functions HOT 5
- Webpack compatible version HOT 8
- Q: TypeScript Definition file? HOT 4
- Misleading comments on [im]mutable functions HOT 2
- [Question] Optimized for large ranges of the same value? HOT 3
- Array parser HOT 2
- Memory usage HOT 10
- A `size()` method HOT 3
- The typescript type declaration does not match the structure of the actual module
- Symbol.iterator is missing from the TypeScript types
- Shifts
- iterator: syntax error in IE HOT 9
- As we can construct a bitset object by a Buffer, Can we convert the bitset to Buffer HOT 4
- Unexpected Results HOT 2
- Documentation problem with "set" function HOT 1
- Base 36 constructor HOT 3
- Benchmarks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitset.js.