-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
Use tinyset to optimize in memory cache RAM usage #1507
Conversation
Could you provide benchmarks at a hundred, ten thousand, or a million guilds? Also, any |
The |
Units are in bytes allocated by the system allocator.
Benchmarking memory usage is a lot harder than it needs to be, orz. |
I think this should be behind a feature flag in the |
@@ -479,6 +509,26 @@ mod tests { | |||
); | |||
} | |||
|
|||
/// Test that creating an ID via [`Id::new`] with a value of zero panics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't seem to test for panic on zero.
Documentation should be updated?
This hasn't had much movement since the initial discussion in Discord. Ultimately, we will not be using |
A good chunk of the overhead of in-memory cache comes from the large number of
HashSets
used in a lot of it's data structures.tinyset
provides a set type optimized for holding types that boil down to 64-bit integers. For a good number of cases, it will not allocate any heap memory until several elements are inserted (like small/arrayvec), and is only the size of a pointer otherwise.This PR includes one
unsafe
function, becausetinyset::Fits64
requires one unsafe fn as a part of the trait.To likewise maximize memory savings, when converting to a
u64
for use inSet64
,Id<T>
shuffles the snowflake parts around to shift most of the 1s towards the lower bits.As an alternative, a roaring bitmap might be another alternative.