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
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.
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