Auto merge of #121909 - Zoxc:drop-ast-task, r=petrochenkov

Drop AST on a separate thread and prefetch `hir_crate`

This drop AST on a separate thread and prefetches `hir_crate`.

A `spawn` function is added to the `parallel` module which spawn some work on the Rayon thread pool.
This commit is contained in:
bors
2025-04-30 23:57:22 +00:00
4 changed files with 26 additions and 3 deletions

View File

@@ -49,6 +49,7 @@ use rustc_attr_parsing::{AttributeParser, OmitDoc};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::spawn;
use rustc_data_structures::tagged_ptr::TaggedRef;
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
@@ -454,9 +455,14 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
.lower_node(def_id);
}
// Drop AST to free memory
drop(ast_index);
sess.time("drop_ast", || drop(krate));
// Drop AST to free memory. It can be expensive so try to drop it on a separate thread.
let prof = sess.prof.clone();
spawn(move || {
let _timer = prof.verbose_generic_activity("drop_ast");
drop(krate);
});
// Don't hash unless necessary, because it's expensive.
let opt_hir_hash =