Compiling `cranelift-codegen` with `-Z next-solver` is very slow
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code: https://github.com/bytecodealliance/wasmtime/ at commit https://github.com/bytecodealliance/wasmtime/commit/201b7b4ce4c5946cce8d5cd90ad2b64440864d8b.
git clone git@github.com: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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the slowdown by checking out commit 201b7b4ce4c5946cce8d5cd90ad2b64440864d8b, entering cranelift/codegen, and running cargo build with and without RUSTFLAGS="-Z next-solver". Start with the perf top entries named in the report, including rustc_next_trait_solver and rustc_middle functions. Done means identifying and addressing the cause of the roughly 10x clean-build slowdown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100