@@ -692,7 +692,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
692
692
let stable_order_of_exportable_impls =
693
693
stat ! ( "exportable-items" , || self . encode_stable_order_of_exportable_impls( ) ) ;
694
694
695
- // Encode exported symbols info. This is prefetched in `encode_metadata`.
695
+ // Encode exported symbols info. This is prefetched in `encode_metadata` so we encode
696
+ // this as late as possible to give the prefetching as much time as possible to complete.
696
697
let ( exported_non_generic_symbols, exported_generic_symbols) =
697
698
stat ! ( "exported-symbols" , || {
698
699
(
@@ -2362,6 +2363,28 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2362
2363
// there's no need to do dep-graph tracking for any of it.
2363
2364
tcx. dep_graph . assert_ignored ( ) ;
2364
2365
2366
+ join (
2367
+ || encode_metadata_impl ( tcx, path, ref_path) ,
2368
+ || {
2369
+ if tcx. sess . threads ( ) == 1 {
2370
+ return ;
2371
+ }
2372
+
2373
+ // Prefetch some queries used by metadata encoding.
2374
+ // This is not necessary for correctness, but is only done for performance reasons.
2375
+ // It can be removed if it turns out to cause trouble or be detrimental to performance.
2376
+ join (
2377
+ || prefetch_mir ( tcx) ,
2378
+ || {
2379
+ let _ = tcx. exported_non_generic_symbols ( LOCAL_CRATE ) ;
2380
+ let _ = tcx. exported_generic_symbols ( LOCAL_CRATE ) ;
2381
+ } ,
2382
+ ) ;
2383
+ } ,
2384
+ ) ;
2385
+ }
2386
+
2387
+ fn encode_metadata_impl ( tcx : TyCtxt < ' _ > , path : & Path , ref_path : Option < & Path > ) {
2365
2388
// Generate the metadata stub manually, as that is a small file compared to full metadata.
2366
2389
if let Some ( ref_path) = ref_path {
2367
2390
let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata_stub" ) ;
@@ -2399,19 +2422,6 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2399
2422
return ;
2400
2423
} ;
2401
2424
2402
- if tcx. sess . threads ( ) != 1 {
2403
- // Prefetch some queries used by metadata encoding.
2404
- // This is not necessary for correctness, but is only done for performance reasons.
2405
- // It can be removed if it turns out to cause trouble or be detrimental to performance.
2406
- join (
2407
- || prefetch_mir ( tcx) ,
2408
- || {
2409
- let _ = tcx. exported_non_generic_symbols ( LOCAL_CRATE ) ;
2410
- let _ = tcx. exported_generic_symbols ( LOCAL_CRATE ) ;
2411
- } ,
2412
- ) ;
2413
- }
2414
-
2415
2425
// Perform metadata encoding inside a task, so the dep-graph can check if any encoded
2416
2426
// information changes, and maybe reuse the work product.
2417
2427
tcx. dep_graph . with_task (
0 commit comments