22c34f3c4c
These commits pick off some low-hanging fruit which were slowing down spawning green threads. The major speedup comes from fixing a bug in stack caching where we never used any cached stacks! The program I used to benchmark is at the end. It was compiled with `rustc --opt-level=3 bench.rs --test` and run as `RUST_THREADS=1 ./bench --bench`. I chose to use `RUST_THREADS=1` due to #11730 as the profiles I was getting interfered too much when all the schedulers were in play (and shouldn't be after #11730 is fixed). All of the units below are in ns/iter as reported by `--bench` (lower is better). | | green | native | raw | | ------------- | ----- | ------ | ------ | | osx before | 12699 | 24030 | 19734 | | linux before | 10223 | 125983 | 122647 | | osx after | 3847 | 25771 | 20835 | | linux after | 2631 | 135398 | 122765 | Note that this is *not* a benchmark of spawning green tasks vs native tasks. I put in the native numbers just to get a ballpark of where green tasks are. This is benchmark is *clearly* benefiting from stack caching. Also, OSX is clearly not 5x faster than linux, I think my VM is just much slower. All in all, this ended up being a nice 4x speedup for spawning a green task when you're using a cached stack. ```rust extern mod extra; extern mod native; use std::rt:🧵:Thread; #[bench] fn green(bh: &mut extra::test::BenchHarness) { let (p, c) = SharedChan::new(); bh.iter(|| { let c = c.clone(); spawn(proc() { c.send(()); }); p.recv(); }); } #[bench] fn native(bh: &mut extra::test::BenchHarness) { let (p, c) = SharedChan::new(); bh.iter(|| { let c = c.clone(); native::task::spawn(proc() { c.send(()); }); p.recv(); }); } #[bench] fn raw(bh: &mut extra::test::BenchHarness) { bh.iter(|| { Thread::start(proc() {}).join() }); } ``` |
||
---|---|---|
.. | ||
comm | ||
fmt | ||
io | ||
num | ||
path | ||
rand | ||
rt | ||
sync | ||
unstable | ||
any.rs | ||
ascii.rs | ||
bool.rs | ||
c_str.rs | ||
cast.rs | ||
cell.rs | ||
char.rs | ||
cleanup.rs | ||
clone.rs | ||
cmp.rs | ||
container.rs | ||
default.rs | ||
from_str.rs | ||
gc.rs | ||
hash.rs | ||
hashmap.rs | ||
iter.rs | ||
kinds.rs | ||
lib.rs | ||
libc.rs | ||
local_data.rs | ||
logging.rs | ||
macros.rs | ||
managed.rs | ||
mem.rs | ||
ops.rs | ||
option.rs | ||
os.rs | ||
owned.rs | ||
prelude.rs | ||
ptr.rs | ||
rc.rs | ||
reference.rs | ||
reflect.rs | ||
repr.rs | ||
result.rs | ||
rtdeps.rs | ||
run.rs | ||
str.rs | ||
task.rs | ||
to_bytes.rs | ||
to_str.rs | ||
trie.rs | ||
tuple.rs | ||
unicode.rs | ||
unit.rs | ||
vec_ng.rs | ||
vec.rs |