Skip to content

Commit fb25985

Browse files
committed
rustdoc: Use a BufferedWriter when emitting source
This takes the rendering time of source files for libstd from 12.5s to 0.1s, turns out write! calls the write function *a lot*
1 parent cc17915 commit fb25985

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/librustdoc/html/render.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use std::vec;
2828
use extra::arc::RWArc;
2929
use extra::json::ToJson;
3030
use extra::sort;
31+
use extra::time;
3132

3233
use syntax::ast;
3334
use syntax::ast_util::is_local;
@@ -179,6 +180,8 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
179180
w.flush();
180181
}
181182

183+
info2!("emitting source files");
184+
let started = time::precise_time_ns();
182185
{
183186
let dst = cx.dst.push("src");
184187
mkdir(&dst);
@@ -191,9 +194,14 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
191194
};
192195
crate = folder.fold_crate(crate);
193196
}
197+
let ended = time::precise_time_ns();
198+
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1e9f64);
194199

195-
// Now render the whole crate.
200+
info2!("rendering the whole crate");
201+
let started = time::precise_time_ns();
196202
cx.crate(crate, cache);
203+
let ended = time::precise_time_ns();
204+
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1e9f64);
197205
}
198206

199207
fn write(dst: Path, contents: &str) {
@@ -289,7 +297,8 @@ impl<'self> SourceCollector<'self> {
289297
}
290298
291299
let dst = cur.push(*p.components.last() + ".html");
292-
let mut w = dst.open_writer(io::CreateOrTruncate);
300+
let w = dst.open_writer(io::CreateOrTruncate);
301+
let mut w = BufferedWriter::new(w);
293302

294303
let title = format!("{} -- source", *dst.components.last());
295304
let page = layout::Page {
@@ -299,6 +308,7 @@ impl<'self> SourceCollector<'self> {
299308
};
300309
layout::render(&mut w as &mut io::Writer, &self.cx.layout,
301310
&page, &(""), &Source(contents.as_slice()));
311+
w.flush();
302312
return true;
303313
}
304314
}

src/librustdoc/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn main_args(args: &[~str]) -> int {
146146
}
147147
}
148148
let ended = time::precise_time_ns();
149-
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1000000000f64);
149+
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1e9f64);
150150

151151
return 0;
152152
}

0 commit comments

Comments
 (0)