@@ -677,7 +677,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
677
677
let debugger_visualizers =
678
678
stat ! ( "debugger-visualizers" , || self . encode_debugger_visualizers( ) ) ;
679
679
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.
681
682
let exported_symbols = stat ! ( "exported-symbols" , || {
682
683
self . encode_exported_symbols( tcx. exported_symbols( LOCAL_CRATE ) )
683
684
} ) ;
@@ -2217,13 +2218,21 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) {
2217
2218
// there's no need to do dep-graph tracking for any of it.
2218
2219
tcx. dep_graph . assert_ignored ( ) ;
2219
2220
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
+ }
2226
2234
2235
+ fn encode_metadata_impl ( tcx : TyCtxt < ' _ > , path : & Path ) {
2227
2236
let mut encoder = opaque:: FileEncoder :: new ( path)
2228
2237
. unwrap_or_else ( |err| tcx. dcx ( ) . emit_fatal ( FailCreateFileEncoder { err } ) ) ;
2229
2238
encoder. emit_raw_bytes ( METADATA_HEADER ) ;
0 commit comments