@@ -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.
1414crate 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}
0 commit comments