-
Notifications
You must be signed in to change notification settings - Fork 1.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
feat: introduce global thread pool and rename ShellOtps
to GlobalOpts
#9313
base: master
Are you sure you want to change the base?
Conversation
…lobal variables is required
…lobal in nodeargs / anvil top level args
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.
impl looks good! there's a regression re the way rayon thread pool is spawned though, a command like
forge test --show-progress --jobs 3
always fail now with Error: The global thread pool has already been initialized.
same on cast create2
cast create2 --starts-with dead --case-sensitive --deployer 0x0000000000FFe8B47B3e2130213B802212439497 --init-code-hash 0x0c591f26891d6443cf08c5be3584c1e6ae10a4c2f07c5c53218741e9755fb9cd --jobs 5
fails with
Error: The global thread pool has already been initialized.
I think we should keep the current behavior, that is if --jobs
flag not passed then we use rayon default (the number of CPUs available) instead single thread.
Probably this one should also follow the config
foundry/crates/cast/src/lib.rs
Lines 2062 to 2063 in a65a5b1
let num_threads = std::thread::available_parallelism().map_or(1, |n| n.get()); | |
let found = AtomicBool::new(false); |
Thanks, good catch!
I had implemented it this way to avoid spawning the global thread pool as the vast majority of commands are not multi-threaded, cc @DaniPopes should we spawn by default? |
crates/chisel/bin/main.rs
Outdated
let args = Chisel::parse(); | ||
args.shell.shell().set(); | ||
args.global.try_spawn()?; |
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.
maybe we can have an "init" that does both of these?
let found = Arc::new(AtomicBool::new(false)); | ||
let timer = Instant::now(); | ||
|
||
// Loops through all possible salts in parallel until a result is found. | ||
// Each thread iterates over `(i..).step_by(n_threads)`. | ||
for i in 0..n_threads { |
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.
Shouldn't change this, rayon has some overhead here
if let Some(num_threads) = num_threads { | ||
return Some(num_threads.min(2)); | ||
} | ||
} |
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.
This is actually the opposite, it caps at 2; this was just to reduce pressure on tests in cast create2, should keep it there
Motivation
Closes: #8408
Solution
--jobs
flag. If not passed it is not spawned. If passed as--jobs 0
it will use the default Rayon configuration (number of logical CPUs).ShellOpts
toGlobalOpts
.GlobalOpts
where required, this can be the case when wanting to indicate aconflicts_with
a global argument or you need access to the thread pool. In most cases when checking against the shell configuration it is probably easier to use the e.g.shell::is_json
variant over passing it all the way down.