Skip to content

Commit 1d1010f

Browse files
committed
Add more timing info to render_html
- Show `create_renderer` and `renderer_after_crate` by default - Don't rewrite `extra_verbose_generic_activity`
1 parent bf86fd5 commit 1d1010f

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

src/librustdoc/formats/renderer.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use crate::formats::cache::{Cache, CACHE_KEY};
1212
/// backend renderer has hooks for initialization, documenting an item, entering and exiting a
1313
/// module, and cleanup/finalizing output.
1414
crate trait FormatRenderer<'tcx>: Clone {
15+
/// Gives a description of the renderer. Used for performance profiling.
16+
fn descr() -> &'static str;
17+
1518
/// Sets up any state required for the renderer. When this is called the cache has already been
1619
/// populated.
1720
fn init(
@@ -57,16 +60,20 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
5760
edition: Edition,
5861
tcx: ty::TyCtxt<'tcx>,
5962
) -> Result<(), Error> {
60-
let (krate, mut cache) = Cache::from_krate(
61-
render_info.clone(),
62-
options.document_private,
63-
&options.extern_html_root_urls,
64-
&options.output,
65-
krate,
66-
);
67-
68-
let (mut format_renderer, mut krate) =
69-
T::init(krate, options, render_info, edition, &mut cache, tcx)?;
63+
let (krate, mut cache) = tcx.sess.time("create_format_cache", || {
64+
Cache::from_krate(
65+
render_info.clone(),
66+
options.document_private,
67+
&options.extern_html_root_urls,
68+
&options.output,
69+
krate,
70+
)
71+
});
72+
let prof = &tcx.sess.prof;
73+
74+
let (mut format_renderer, mut krate) = prof
75+
.extra_verbose_generic_activity("create_renderer", T::descr())
76+
.run(|| T::init(krate, options, render_info, edition, &mut cache, tcx))?;
7077

7178
let cache = Arc::new(cache);
7279
// Freeze the cache now that the index has been built. Put an Arc into TLS for future
@@ -83,6 +90,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
8390
// Render the crate documentation
8491
let mut work = vec![(format_renderer.clone(), item)];
8592

93+
let unknown = rustc_span::Symbol::intern("<unknown item>");
8694
while let Some((mut cx, item)) = work.pop() {
8795
if item.is_mod() {
8896
// modules are special because they add a namespace. We also need to
@@ -91,6 +99,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
9199
if name.is_empty() {
92100
panic!("Unexpected module with empty name");
93101
}
102+
let _timer = prof.generic_activity_with_arg("render_mod_item", name.as_str());
94103

95104
cx.mod_item_in(&item, &name, &cache)?;
96105
let module = match *item.kind {
@@ -104,9 +113,10 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
104113

105114
cx.mod_item_out(&name)?;
106115
} else if item.name.is_some() {
107-
cx.item(item, &cache)?;
116+
prof.generic_activity_with_arg("render_item", &*item.name.unwrap_or(unknown).as_str())
117+
.run(|| cx.item(item, &cache))?;
108118
}
109119
}
110-
111-
format_renderer.after_krate(&krate, &cache, diag)
120+
prof.extra_verbose_generic_activity("renderer_after_krate", T::descr())
121+
.run(|| format_renderer.after_krate(&krate, &cache, diag))
112122
}

src/librustdoc/html/render/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ crate fn initial_ids() -> Vec<String> {
384384

385385
/// Generates the documentation for `crate` into the directory `dst`
386386
impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
387+
fn descr() -> &'static str {
388+
"html"
389+
}
390+
387391
fn init(
388392
mut krate: clean::Crate,
389393
options: RenderOptions,

src/librustdoc/json/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ impl JsonRenderer<'_> {
125125
}
126126

127127
impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
128+
fn descr() -> &'static str {
129+
"json"
130+
}
131+
128132
fn init(
129133
krate: clean::Crate,
130134
options: RenderOptions,

0 commit comments

Comments
 (0)