-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Hash VecDeque in its slice parts #31224
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Benchmark code: https://gist.github.com/bluss/a021d1a71b2709dbf724 |
@_@ DAT PERF 💯 |
Can you add a test that verifies that different splits yield the same hash? Something like pushpushpush == pushpushpoppushpush |
Also: dang! Should we be doing this for eq/ord, etc? |
I'm working on this for eq. We should absolutely use slices everywhere we can (llvm likes them, see #30805). A test to verify same hash, same eq for different splits sounds good. Will do. |
89a36a2
to
e62ebb9
Compare
I added a test! |
for elt in &mut ring { | ||
*elt -= 1; | ||
} | ||
ring.push_back(first + len - 1); |
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.
first == 0, so this is just len - 1
?
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.
smart. yes.. why think?
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.
I'm fixing it.
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.
fixed
Use .as_slices() for a more efficient code path in VecDeque's Hash impl. This still hashes the elements in the same order. Before/after timing of VecDeque hashing 1024 elements of u8 and u64 shows that the vecdeque now can match the Vec (test_hashing_vec_of_u64 is the Vec run). before test test_hashing_u64 ... bench: 14,031 ns/iter (+/- 236) = 583 MB/s test test_hashing_u8 ... bench: 7,887 ns/iter (+/- 65) = 129 MB/s test test_hashing_vec_of_u64 ... bench: 6,578 ns/iter (+/- 76) = 1245 MB/s after running 5 tests test test_hashing_u64 ... bench: 6,495 ns/iter (+/- 52) = 1261 MB/s test test_hashing_u8 ... bench: 851 ns/iter (+/- 16) = 1203 MB/s test test_hashing_vec_of_u64 ... bench: 6,499 ns/iter (+/- 59) = 1260 MB/s
@bors r+ |
📌 Commit d3174ce has been approved by |
Thanks for the feedback Gankro! Together we will hash these bytes, faster than ever. |
Hash VecDeque in its slice parts Use .as_slices() for a more efficient code path in VecDeque's Hash impl. This still hashes the elements in the same order. Before/after timing of VecDeque hashing 1024 elements of u8 and u64 shows that the vecdeque now can match the Vec (test_hashing_vec_of_u64 is the Vec run). ``` before test test_hashing_u64 ... bench: 14,031 ns/iter (+/- 236) = 583 MB/s test test_hashing_u8 ... bench: 7,887 ns/iter (+/- 65) = 129 MB/s test test_hashing_vec_of_u64 ... bench: 6,578 ns/iter (+/- 76) = 1245 MB/s after running 5 tests test test_hashing_u64 ... bench: 6,495 ns/iter (+/- 52) = 1261 MB/s test test_hashing_u8 ... bench: 851 ns/iter (+/- 16) = 1203 MB/s test test_hashing_vec_of_u64 ... bench: 6,499 ns/iter (+/- 59) = 1260 MB/s ```
Hash VecDeque in its slice parts
Use .as_slices() for a more efficient code path in VecDeque's Hash impl.
This still hashes the elements in the same order.
Before/after timing of VecDeque hashing 1024 elements of u8 and
u64 shows that the vecdeque now can match the Vec
(test_hashing_vec_of_u64 is the Vec run).