Skip to content

Slow compilation of actix-web routes #140944

Open
@Nutomic

Description

@Nutomic

I noticed that Rust is extremely slow to compile a rather simple file containing route definitions for the actix-web webserver. It has 200 lines of imports, 250 lines of code and no macros, yet takes ~60s to compile. Duration is the same on Rust 1.81, 1.86 and nightly-2025-04-27.

Here is an excerpt from the profiling data, and you can also view the .mm_profdata.

Item Self time % of total time Time Item count Incremental result hashing time
layout_of 29.25s 42.066 111.38s 123703 32.73ms
normalize_canonicalized_projection_ty 17.28s 24.851 18.07s 15554 5.31ms
codegen_select_candidate 9.16s 13.173 9.39s 28989 9.75ms
LLVM_module_codegen_emit_obj 5.59s 8.042 5.59s 256 0.00ns
LLVM_passes 2.13s 3.069 2.13s 1 0.00ns
codegen_module 1.40s 2.009 4.43s 256 0.00ns
evaluate_obligation 951.66ms 1.369 1.03s 47932 7.69ms
items_of_instance 301.15ms 0.433 56.05s 57443 34.90ms

Whats strange is that the same file on the main branch takes only ~25s to compile (which is still too long). There it is part of the main binary crate.

To reproduce run:

git clone https://github.com/LemmyNet/lemmy.git --recursive --branch api-routes-crate
cd lemmy
cargo build --timings -p lemmy_api_routes

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions