@@ -677,7 +677,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
677677 let debugger_visualizers =
678678 stat ! ( "debugger-visualizers" , || self . encode_debugger_visualizers( ) ) ;
679679
680- // Encode exported symbols info. This is prefetched in `encode_metadata`.
680+ // Encode exported symbols info. This is prefetched in `encode_metadata` so we encode
681+ // this as late as possible to give the prefetching as much time as possible to complete.
681682 let exported_symbols = stat ! ( "exported-symbols" , || {
682683 self . encode_exported_symbols( tcx. exported_symbols( LOCAL_CRATE ) )
683684 } ) ;
@@ -2217,13 +2218,21 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) {
22172218 // there's no need to do dep-graph tracking for any of it.
22182219 tcx. dep_graph . assert_ignored ( ) ;
22192220
2220- if tcx. sess . threads ( ) != 1 {
2221- // Prefetch some queries used by metadata encoding.
2222- // This is not necessary for correctness, but is only done for performance reasons.
2223- // It can be removed if it turns out to cause trouble or be detrimental to performance.
2224- join ( || prefetch_mir ( tcx) , || tcx. exported_symbols ( LOCAL_CRATE ) ) ;
2225- }
2221+ join (
2222+ || encode_metadata_impl ( tcx, path) ,
2223+ || {
2224+ if tcx. sess . threads ( ) == 1 {
2225+ return ;
2226+ }
2227+ // Prefetch some queries used by metadata encoding.
2228+ // This is not necessary for correctness, but is only done for performance reasons.
2229+ // It can be removed if it turns out to cause trouble or be detrimental to performance.
2230+ join ( || prefetch_mir ( tcx) , || tcx. exported_symbols ( LOCAL_CRATE ) ) ;
2231+ } ,
2232+ ) ;
2233+ }
22262234
2235+ fn encode_metadata_impl ( tcx : TyCtxt < ' _ > , path : & Path ) {
22272236 let mut encoder = opaque:: FileEncoder :: new ( path)
22282237 . unwrap_or_else ( |err| tcx. dcx ( ) . emit_fatal ( FailCreateFileEncoder { err } ) ) ;
22292238 encoder. emit_raw_bytes ( METADATA_HEADER ) ;
0 commit comments