-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
perf(core): simplify bloom bucket computation #40489
Conversation
The injector system uses a bloom filter to determine if a token is possibly defined in the node injector tree, which is stored across multiple bloom buckets that each represent 32 bits of the full 256-bit wide bloom hash. This means that a computation is required to determine the exact bloom bucket which is responsible for storing any given 32-bit interval, which was previously computed using three bitmask operations and three branches to derive the bloom bucket offset. This commit exploits the observation that all bits beyond the low 5 bits of the bloom hash are an accurate representation for the bucket offset, if shifted right such that those bits become the least significant bits. This reduces the three bitmask operations and three branches with a single shift operation, while additionally offering a code size improvement.
…re handled correctly This commits adds additional expectations to verify that the bloom filter is able to correctly handle token IDs that exceed the size of the bloom filter (which is currently 256 bits).
6c5582c
to
017eee3
Compare
Sexy <3 |
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.
❤️
// Each bloom bucket in `tData` represents `BLOOM_BUCKET_BITS` number of bits of `bloomHash`. | ||
// Any bits in `bloomHash` beyond `BLOOM_BUCKET_BITS` indicate the bucket offset that the mask | ||
// should be written to. | ||
(tView.data as number[])[injectorIndex + (bloomHash >> BLOOM_BUCKET_BITS)] |= mask; |
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.
Ok, that is clear! I can't believe I did not think of that! 😊
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.
reviewed-for: size-tracking
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.
LGTM
Very nice! Thank you.
Reviewed-for: size-tracking
The injector system uses a bloom filter to determine if a token is possibly defined in the node injector tree, which is stored across multiple bloom buckets that each represent 32 bits of the full 256-bit wide bloom hash. This means that a computation is required to determine the exact bloom bucket which is responsible for storing any given 32-bit interval, which was previously computed using three bitmask operations and three branches to derive the bloom bucket offset. This commit exploits the observation that all bits beyond the low 5 bits of the bloom hash are an accurate representation for the bucket offset, if shifted right such that those bits become the least significant bits. This reduces the three bitmask operations and three branches with a single shift operation, while additionally offering a code size improvement. PR Close #40489
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The injector system uses a bloom filter to determine if a token is
possibly defined in the node injector tree, which is stored across
multiple bloom buckets that each represent 32 bits of the full 256-bit
wide bloom hash. This means that a computation is required to determine
the exact bloom bucket which is responsible for storing any given 32-bit
interval, which was previously computed using three bitmask operations
and three branches to derive the bloom bucket offset.
This commit exploits the observation that all bits beyond the low 5 bits
of the bloom hash are an accurate representation for the bucket offset,
if shifted right such that those bits become the least significant bits.
This reduces the three bitmask operations and three branches with a
single shift operation, while additionally offering a code size
improvement.