@@ -665,7 +665,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
665
665
let debugger_visualizers =
666
666
stat ! ( "debugger-visualizers" , || self . encode_debugger_visualizers( ) ) ;
667
667
668
- // Encode exported symbols info. This is prefetched in `encode_metadata`.
668
+ // Encode exported symbols info. This is prefetched in `encode_metadata` so we encode
669
+ // this as late as possible to give the prefetching as much time as possible to complete.
669
670
let exported_symbols = stat ! ( "exported-symbols" , || {
670
671
self . encode_exported_symbols( tcx. exported_symbols( LOCAL_CRATE ) )
671
672
} ) ;
@@ -2203,13 +2204,21 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) {
2203
2204
// there's no need to do dep-graph tracking for any of it.
2204
2205
tcx. dep_graph . assert_ignored ( ) ;
2205
2206
2206
- if tcx. sess . threads ( ) != 1 {
2207
- // Prefetch some queries used by metadata encoding.
2208
- // This is not necessary for correctness, but is only done for performance reasons.
2209
- // It can be removed if it turns out to cause trouble or be detrimental to performance.
2210
- join ( || prefetch_mir ( tcx) , || tcx. exported_symbols ( LOCAL_CRATE ) ) ;
2211
- }
2207
+ join (
2208
+ || encode_metadata_impl ( tcx, path) ,
2209
+ || {
2210
+ if tcx. sess . threads ( ) == 1 {
2211
+ return ;
2212
+ }
2213
+ // Prefetch some queries used by metadata encoding.
2214
+ // This is not necessary for correctness, but is only done for performance reasons.
2215
+ // It can be removed if it turns out to cause trouble or be detrimental to performance.
2216
+ join ( || prefetch_mir ( tcx) , || tcx. exported_symbols ( LOCAL_CRATE ) ) ;
2217
+ } ,
2218
+ ) ;
2219
+ }
2212
2220
2221
+ fn encode_metadata_impl ( tcx : TyCtxt < ' _ > , path : & Path ) {
2213
2222
let mut encoder = opaque:: FileEncoder :: new ( path)
2214
2223
. unwrap_or_else ( |err| tcx. dcx ( ) . emit_fatal ( FailCreateFileEncoder { err } ) ) ;
2215
2224
encoder. emit_raw_bytes ( METADATA_HEADER ) ;
0 commit comments