Skip to content
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: better cast create2 #6212

Merged
merged 4 commits into from
Nov 3, 2023
Merged

Conversation

DaniPopes
Copy link
Member

Motivation

Speed

Solution

Make faster

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speed gud

Comment on lines 148 to 149
let salt_word = unsafe { &mut *salt.0.as_mut_ptr().cast::<usize>() };
*salt_word = start;
Copy link
Member

@mattsse mattsse Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not obvious what's going on here, this sets the salt's first word to the thread's index incrementing it by the number of threads, so the salt cycles through all unique values?

needs docs+SAFETY

salt uses u64 internally? should this cast to u64? read b256 aligned wrong, or maybe not idk

Copy link
Member Author

@DaniPopes DaniPopes Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n_threads=4

  • (thread)i=0: word=0; word=4; word=8
  • (thread)i=1: word=1; word=5; word=9
  • (thread)i=2: word=2; word=6; word=10
  • (thread)i=3: word=3; word=7; word=11

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha create2 go brrrr

same as matt, just more docs would be nice!

@DaniPopes
Copy link
Member Author

Added

let salt_word = unsafe { &mut *salt.0.as_mut_ptr().cast::<usize>() };
*salt_word = start;

// Important: set the salt to the start value, otherwise all threads loop over the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the loop only covers u64 or u32 depending on the arch, so not all the available 32bytes?

fine?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>> u32::MAX / 128
33554431
>> u64::MAX / 128
144115188075855871

iterations needed to overflow, I don't think that's reachable

@DaniPopes DaniPopes merged commit fa6b39c into foundry-rs:master Nov 3, 2023
16 checks passed
@DaniPopes DaniPopes deleted the better-create2 branch November 3, 2023 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants