Skip to content
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

Memory usage of []bool #1

Open
Deleplace opened this issue Dec 19, 2017 · 3 comments
Open

Memory usage of []bool #1

Deleplace opened this issue Dec 19, 2017 · 3 comments

Comments

@Deleplace
Copy link

While a []bool is great for simplicity, I suspect it takes much more space in memory than a "compact" Bitset. This would be caused by the memory layout of the underlying array, where each bool is individually addressable.

This is important because Bloom filters are designed specifically to be space-efficient, storing only the conflated Bitset instead all the elements themselves, or even all the hash values.

Go has no built-in Bitset type, but it seems that a common and efficient ready-to-use Bitset implementation is *big.Int. (I created an idiomatic snippet here).

It would be interesting to run a "memory usage" benchmark of []bool vs *big.Int. The speed performance results would be interesting as well (I have no idea which one wins on speed!). Fanis, what do you think?

@theodesp
Copy link
Owner

theodesp commented Dec 19, 2017

Hello @Deleplace. Yes, I think []bool is not the most space efficient model for that. If you check some other implementations of Bloom Filters they use either the @willf one:

https://github.com/willf/bitset/blob/master/bitset.go

or a plain []uint64 slice with the rationale that they are more space efficient.

For me, as you said I only did it as a simplified example as It would be strange to talk about boolean values and not use a boolean slice.

I have a relevant article on medium on that>
https://codeburst.io/lets-implement-a-bloom-filter-in-go-b2da8a4b849f

@Deleplace
Copy link
Author

Great article :) that's where I came from initially

@Deleplace
Copy link
Author

I didn't know about willf/bitset, cool. More complex than *big.Int, but also more performant (I measured).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants