Skip to content

Compiling cranelift-codegen with -Z next-solver is very slow #131411

Open
@narpfel

Description

@narpfel

I tried this code: https://github.com/bytecodealliance/wasmtime/ at commit bytecodealliance/wasmtime@201b7b4.

git clone [email protected]:bytecodealliance/wasmtime.git
cd wasmtime
git checkout 201b7b4ce4c5946cce8d5cd90ad2b64440864d8b
cd cranelift/codegen
RUSTFLAGS="-Z next-solver" cargo build

I expected to see this happen: cargo build should succeed in a couple of seconds (which it does without -Z next-solver).

Instead, this happened: A clean rebuild with-Z next-solver takes 10x longer than without.

These are the hottest functions according to perf top:

   6,25%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::TyCtxt>::mk_args
   5,49%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt>>::evaluate_goal_raw
   5,08%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::CtxtInterners>::intern_ty
   4,16%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::CtxtInterners>::intern_predicate
   3,80%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::canonicalizer::Canonicalizer<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
   2,74%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::resolve::EagerResolver<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_predicate
   2,39%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::canonicalizer::Canonicalizer<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt>>::finalize
   2,08%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::canonicalizer::Canonicalizer<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_predicate
   1,94%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_trait_selection::solve::fulfill::FulfillmentCtxt<rustc_trait_selection::traits::FulfillmentError> as rustc_infer::traits::engine::TraitEngine<rustc_trait_selection::traits::FulfillmentError>>::select_where_possible
   1,83%  librustc_driver-57fe6e1841a504ec.so       [.] <hashbrown::raw::RawTable<((rustc_type_ir::DebruijnIndex, rustc_middle::ty::Ty), rustc_middle::ty::Ty)>>::reserve_rehash::<hashbrown::map::make_hasher<(rustc_type_ir::DebruijnIndex, rustc_middle::ty::Ty), rustc_middle::ty::Ty, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>::{closure#0}>
   1,81%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::TyCtxt>::mk_canonical_var_infos
   1,52%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::TyCtxt>::mk_predefined_opaques_in_body
   1,37%  librustc_driver-57fe6e1841a504ec.so       [.] <hashbrown::map::HashMap<(rustc_type_ir::DebruijnIndex, rustc_middle::ty::Ty), rustc_middle::ty::Ty, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>>::insert

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.83.0-nightly (3ae715c8c 2024-10-07)
binary: rustc
commit-hash: 3ae715c8c63f9aeac47cbf7d8d9dadb3fa32c638
commit-date: 2024-10-07
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions