]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #8317 : bblum/rust/fast-spawn-unlinked, r=brson
authorbors <bors@rust-lang.org>
Tue, 6 Aug 2013 17:32:00 +0000 (10:32 -0700)
committerbors <bors@rust-lang.org>
Tue, 6 Aug 2013 17:32:00 +0000 (10:32 -0700)
This lazily initializes the taskgroup structs for ```spawn_unlinked``` tasks. If such a task never spawns another task linked to it (or a descendant of it), its taskgroup is simply never initialized at all. Also if an unlinked task spawns another unlinked task, neither of them will need to initialize their taskgroups. This works for the main task too.

I benchmarked this with the following test case and observed a ~~21% speedup (average over 4 runs: 7.85 sec -> 6.20 sec, 2.5 GHz)~~ 11% speedup, see comment below.
```
use std::task;
use std::cell::Cell;
use std::rt::comm;

static NUM: uint = 1024*256;

fn run(f: ~fn()) {
    let mut t = task::task();
    t.unlinked();
    t.spawn(f);
}

fn main() {
    do NUM.times {
        let (p,c) = comm::oneshot();
        let c = Cell::new(c);
        do run { c.take().send(()); }
        p.recv();
    }
}
```


Trivial merge