diff options
| author | kennytm <kennytm@gmail.com> | 2018-09-08 16:07:42 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-09-08 18:26:39 +0800 |
| commit | 14c21a11b31b54c0fa237d593880c8164e0db564 (patch) | |
| tree | a2a9d7ec78ac2626e7c03a1dd55c16e9f3c6b71a /src/test/incremental/thinlto | |
| parent | 5cc51add43bffa21bab4708a53a1920c9671ea8a (diff) | |
| parent | 28745a6e190a8c61ba2f08b03ea8afed620c9735 (diff) | |
| download | rust-14c21a11b31b54c0fa237d593880c8164e0db564.tar.gz rust-14c21a11b31b54c0fa237d593880c8164e0db564.zip | |
Rollup merge of #53981 - fbernier:patch-1, r=sfackler
Implement initializer() for FileDesc
Here was my initial issue:
```rust
use std::process::{Command};
fn main() {
let output = Command::new("curl").arg("-s").arg("http://ovh.net/files/100Mio.dat").output();
println!("{:?}", output.unwrap().stdout.len());
}
```
```
~/stuff ❯❯❯ time ./dwl
104857600
./dwl 16.22s user 1.80s system 23% cpu 1:15.24 total
```
```rust
use std::process::{Command, Stdio};
fn main() {
let child = Command::new("curl").arg("-s").arg("http://ovh.net/files/100Mio.dat").stdout(Stdio::piped()).spawn();
let output = child.unwrap().wait_with_output().unwrap();
println!("{:?}", output.stdout.len());
}
```
```
~/stuff ❯❯❯ time ./dwl2
104857600
./dwl2 0.64s user 2.18s system 5% cpu 53.072 total
```
As you can see the first version is spending much more time in userland and also uses more cpu. With the help of @programble, @talchas and @habnabit on the rust IRC, we discovered that the slow version uses two pipes, one for `stdin` and one for `stderr` and in that case it polls when going through [this function](https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/pipe.rs#L82). The polling calls `read_to_end` on the pipes repetitively and this results in zeroing its internal buffer each time. To avoid this zeroing, `FileDesc` needs to implement `initializer`. We see no reason why it [wouldn't work with uninitialized memory](https://doc.rust-lang.org/1.26.1/src/std/io/mod.rs.html#534) so this PR fixes that.
Here is some tracing of the slow program:

versus the fast program:

I have not tested the change yet but will try to build it tomorrow.
Diffstat (limited to 'src/test/incremental/thinlto')
0 files changed, 0 insertions, 0 deletions
