rust/src/libstd
bors 22c34f3c4c auto merge of #12172 : alexcrichton/rust/green-improvements, r=brson
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()
    });
}
```
2014-02-13 20:36:55 -08:00
..
comm Rebase conflicts from this giant stack of patches 2014-02-13 13:33:46 -08:00
fmt Move replace and swap to std::mem. Get rid of std::util 2014-02-11 05:21:35 +08:00
io Removed num::Orderable 2014-02-13 20:12:59 -05:00
num Removed num::Orderable 2014-02-13 20:12:59 -05:00
path Rewrite path::Display to reduce unnecessary allocation 2014-02-07 22:31:52 -08:00
rand
rt Don't require an allocation for on_exit messages 2014-02-13 20:29:47 -08:00
sync Rewrite channels yet again for upgradeability 2014-02-11 16:32:00 -08:00
unstable Remove two allocations from spawning a green task 2014-02-13 20:31:17 -08:00
any.rs Add some missing Show implementations in libstd 2014-02-13 12:54:01 -08:00
ascii.rs Add some missing Show implementations in libstd 2014-02-13 12:54:01 -08:00
bool.rs
c_str.rs remove duplicate function from std::ptr (is_null, is_not_null, offset, mut_offset) 2014-02-13 12:54:17 -08:00
cast.rs std: Stop parameterizing some memcpy functions over RawPtr 2014-02-09 16:23:10 -08:00
cell.rs
char.rs
cleanup.rs Register new snapshots 2014-02-13 12:54:17 -08:00
clone.rs
cmp.rs Removed num::Orderable 2014-02-13 20:12:59 -05:00
container.rs
default.rs
from_str.rs
gc.rs
hash.rs
hashmap.rs Removed num::Orderable 2014-02-13 20:12:59 -05:00
iter.rs Fix broken link to the container guide 2014-02-11 14:38:36 +00:00
kinds.rs
lib.rs Move replace and swap to std::mem. Get rid of std::util 2014-02-11 05:21:35 +08:00
libc.rs Fix the signature of CreateSymbolicLinkW 2014-02-09 11:54:19 -08:00
local_data.rs Move replace and swap to std::mem. Get rid of std::util 2014-02-11 05:21:35 +08:00
logging.rs Move replace and swap to std::mem. Get rid of std::util 2014-02-11 05:21:35 +08:00
macros.rs Lift $dst outside the closure in write! 2014-02-13 13:05:48 -08:00
managed.rs
mem.rs Move replace and swap to std::mem. Get rid of std::util 2014-02-11 05:21:35 +08:00
ops.rs
option.rs Move replace and swap to std::mem. Get rid of std::util 2014-02-11 05:21:35 +08:00
os.rs std::fmt: convert the formatting traits to a proper self. 2014-02-08 13:53:21 +11:00
owned.rs
prelude.rs Removed num::Orderable 2014-02-13 20:12:59 -05:00
ptr.rs remove duplicate function from std::ptr (is_null, is_not_null, offset, mut_offset) 2014-02-13 12:54:17 -08:00
rc.rs
reference.rs
reflect.rs Register new snapshots 2014-02-13 12:54:17 -08:00
repr.rs remove duplicate function from std::ptr (is_null, is_not_null, offset, mut_offset) 2014-02-13 12:54:17 -08:00
result.rs std::fmt: convert the formatting traits to a proper self. 2014-02-08 13:53:21 +11:00
rtdeps.rs
run.rs Rewrite channels yet again for upgradeability 2014-02-11 16:32:00 -08:00
str.rs remove duplicate function from std::ptr (is_null, is_not_null, offset, mut_offset) 2014-02-13 12:54:17 -08:00
task.rs Rewrite channels yet again for upgradeability 2014-02-11 16:32:00 -08:00
to_bytes.rs
to_str.rs
trie.rs Move replace and swap to std::mem. Get rid of std::util 2014-02-11 05:21:35 +08:00
tuple.rs
unicode.rs
unit.rs Add some missing Show implementations in libstd 2014-02-13 12:54:01 -08:00
vec_ng.rs remove duplicate function from std::ptr (is_null, is_not_null, offset, mut_offset) 2014-02-13 12:54:17 -08:00
vec.rs remove duplicate function from std::ptr (is_null, is_not_null, offset, mut_offset) 2014-02-13 12:54:17 -08:00