Improve seeding and initialize thread-local non-determinism with fresh entropy#48
Open
orlp wants to merge 4 commits into
Open
Improve seeding and initialize thread-local non-determinism with fresh entropy#48orlp wants to merge 4 commits into
orlp wants to merge 4 commits into
Conversation
Owner
Author
|
@hoxxep Want to take a look? |
Contributor
|
The logic looks sound. My only thought would be that it does 11 mixes, two syscalls, an allocation, and an atomic load/store for every new thread, which seems like a lot? It's much more straightforward to reason about than my approach though, so it LGTM. |
Owner
Author
use std::time::Duration;
fn main() {
let iters = 1_000_000;
let mut times = [0.0; 2];
for iter in 0..iters {
let start = std::time::Instant::now();
std::thread::scope(|s| {
s.spawn(|| {
if iter % 2 == 1 {
core::hint::black_box(foldhash::quality::RandomState::default());
}
times[iter % 2] += start.elapsed().as_secs_f64();
});
});
}
let without = Duration::from_secs_f64(times[0] / iters as f64);
let with = Duration::from_secs_f64(times[1] / iters as f64);
let overhead = with - without;
eprintln!("Without: {without:?}");
eprintln!("With: {with:?}");
eprintln!("Overhead: {overhead:?} ({:.2}%)", 100.0 * (times[1] / times[0] - 1.0));
}On my Apple M2 this prints: Without: 5.993µs
With: 6.126µs
Overhead: 133ns (2.22%)I'm honestly surprised the thread spawn is even remotely that fast. And if you care about 0.1us latency on a thread spawn you're probably doing things wrong and should have a pre-spawned thread pool anyway. |
Contributor
|
Good point, it looks good to me! |
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.
Fixes #47.