Would it help to if internal arrays were sparse?
See original GitHub issuehttps://github.com/lemire/FastBitSet.js/blob/master/FastBitSet.js#L120 initialises the enlarged array slots to 0
.
I wonder if it would be better to have a hole there instead?
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (10 by maintainers)
Top Results From Across the Web
Why are we allowed to create sparse arrays in JavaScript?
Arrays that are sufficiently sparse are typically implemented in a slower, more memory-efficient way than dense arrays are`. "more memory- ...
Read more >efficiency of sparse array creation - Google Groups
Creating sparse arrays seems exceptionally slow. I can set up the non-zero data of the array relatively quickly. For example, the following code...
Read more >A Gentle Introduction to Sparse Matrices for Machine Learning
The sparse matrix is represented using three one-dimensional arrays for the non-zero values, the extents of the rows, and the column indexes.
Read more >Working with Sparse Arrays - Wolfram Language Documentation
Sparse representations of matrices are useful because they do not store every element. If one particular value appears very frequently it can be...
Read more >How does MATLAB internally store sparse arrays / Calling ...
MATLAB stores sparse matrices in the CSC 0-based format, except MATLAB does not store the pointerB and pointerE info the same way. MATLAB...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dimaqq
I think that an typed array will use far less memory, at least in some instances, but it is not due to optimizations related to having ‘mostly zeroes’.
Given that they were designed to be passed to underlying C/C++ functions, it would violate my expectations that they relied on anything by a flat array. Of course, if you never touch the memory, at all, you may not hit RAM at all, the pages may never be mapped. That is, there is a big difference between “untouched” and “mostly zeros”.
We can test it out…
This works, and I find that the memory usage is almost nil.
And voilà… node reports 4GB of memory usage.
Let us see how much memory an array takes…
I find that about 16 bytes per entry are used.
Do you confirm?
The dependencies in JavaScript are a bit insane but I don’t think that the roaring package started it.
The
TypedFastBitSet
is backed bynew Uint32Array(size)
so there is no “hole”. It may use less memory thanFastBitSet
but not because of the holes.The good thing with a BitSet, backed by an array, is that has predictably good performance… and also have a predictable memory usage.
To illustrate, let me run the current benchmark… First, with the code in master…
Next, let us remove line 120 and rerun the benchmark…
So you go from 14,000 operations per second to 3,000 operations per second. It is several times slower. Not good.
Have you considered roaring? It should use less memory than just about anything else, and it is going to be really, really fast… Let me try again with
roaring
…See how we are several times faster than
FastBitSet
?