Save an instruction in EntityHasher#10648
Merged
mockersf merged 2 commits intobevyengine:mainfrom Nov 28, 2023
Merged
Conversation
superdump
approved these changes
Nov 20, 2023
james7132
approved these changes
Nov 25, 2023
Member
james7132
left a comment
There was a problem hiding this comment.
This looks good, with the appropriate tests and documentation all the way through. One thing that did bother me about #10605 was that the stress tests seemed to show improvements that were potentially within the margin of error. I know this is asking more from an already thorough PR, but could you rerun those stress tests to see if the improvements are still there?
mockersf
approved these changes
Nov 25, 2023
Member
mockersf
left a comment
There was a problem hiding this comment.
(and also rebase or merge main in to get the latest change in CI)
Member
|
Can you please rebase / merge in main to get the latest CI check running on your PR? |
332d085 to
462687a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Keep essentially the same structure of
EntityHasherfrom #9903, but rephrase the multiplication slightly to save an instruction.cc @superdump
Discord thread: https://discord.com/channels/691052431525675048/1172033156845674507/1174969772522356756
Solution
Today, the hash is
with
ibeing(generation << 32) | index.Expanding things out, we get
What if we do the same thing, but with
+instead of|? That's almost the same thing, except that it has carries, which are actually often better in a hash function anyway, since it doesn't saturate. (|can be dangerous, since once something becomes-1it'll stay that, and there's no mixing available.)So we can do essentially the same thing using a single multiplication instead of doing multiply-shift-or.
LLVM was already smart enough to merge the shifting into a multiplication, but this saves the extra

or:https://rust.godbolt.org/z/MEvbz4eo4
It's a very small change, and often will disappear in load latency anyway, but it's a couple percent faster in lookups:

(There was more of an improvement here before #10558, but with
to_bitsbeing a singleqwordload now, keeping things mostly as it is turned out to be better than the bigger changes I'd tried in #10605.)Changelog
(Probably skip it)
Migration Guide
(none needed)