How can this self-profile session help me speed-up the build?

I ran (from Intro to rustc's self profiler | Inside Rust Blog):

cargo rustc -p app -- -Zself-profile
summarize summarize app-0016432

and I got:

summarize summarize app-0016432
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| Item                                                       | Self time | % of total time | Time     | Item count | Incremental load time | Incremental result hashing time |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| codegen_copy_artifacts_from_incr_cache                     | 25.11s    | 85.028          | 25.11s   | 256        | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| run_linker                                                 | 1.01s     | 3.411           | 1.01s    | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| LLVM_passes                                                | 807.35ms  | 2.733           | 807.35ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| codegen_crate                                              | 668.53ms  | 2.263           | 1.69s    | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| copy_all_cgu_workproducts_to_incr_comp_cache_dir           | 210.50ms  | 0.713           | 210.50ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| monomorphization_collector_graph_walk                      | 205.03ms  | 0.694           | 701.18ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_prepare_session_directory                        | 189.93ms  | 0.643           | 189.93ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_decode_entry_optimized_mir                        | 135.63ms  | 0.459           | 135.63ms | 6092       | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_encode_dep_graph                                 | 109.85ms  | 0.372           | 109.85ms | 1369262    | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| cgu_partitioning_place_items                               | 102.95ms  | 0.349           | 130.27ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| items_of_instance                                          | 85.76ms   | 0.290           | 86.07ms  | 1          | 85.68ms               | 900.00ns                        |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_load_dep_graph                                   | 66.63ms   | 0.226           | 66.63ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| optimized_mir                                              | 59.52ms   | 0.202           | 195.52ms | 6092       | 0.00ns                | 58.20ms                         |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| typeck                                                     | 57.44ms   | 0.194           | 96.89ms  | 15         | 869.50µs              | 159.20µs                        |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| assert_symbols_are_distinct                                | 54.60ms   | 0.185           | 100.45ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_register_crate                                    | 51.00ms   | 0.173           | 228.36ms | 280        | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| encode_query_results_for                                   | 46.06ms   | 0.156           | 46.06ms  | 61         | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| trait_impls_of                                             | 39.96ms   | 0.135           | 59.21ms  | 284        | 0.00ns                | 645.10µs                        |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_decode_entry_exported_symbols                     | 39.57ms   | 0.134           | 39.57ms  | 280        | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| symbol_name                                                | 29.37ms   | 0.099           | 29.37ms  | 0          | 29.37ms               | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| find_cgu_reuse                                             | 25.74ms   | 0.087           | 45.69ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_finalize_session_directory                       | 18.65ms   | 0.063           | 18.65ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| cgu_partitioning_internalize_symbols                       | 15.62ms   | 0.053           | 15.62ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_query_cache_promotion                            | 15.56ms   | 0.053           | 25.32ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| collect_and_partition_mono_items                           | 15.04ms   | 0.051           | 977.32ms | 1          | 0.00ns                | 5.61ms                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| link_binary                                                | 14.68ms   | 0.050           | 1.03s    | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| size_estimate                                              | 13.19ms   | 0.045           | 13.19ms  | 0          | 13.19ms               | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_decode_entry_mir_coroutine_witnesses              | 12.53ms   | 0.042           | 12.53ms  | 2525       | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_decode_entry_type_of                              | 11.42ms   | 0.039           | 11.42ms  | 19808      | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| expand_crate                                               | 11.22ms   | 0.038           | 67.56ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| monomorphization_collector                                 | 10.09ms   | 0.034           | 711.50ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+

...others smaller removed here...

Total cpu time: 29.5357557s
+----------------------------+----------------+
| Item                       | Artifact Size  |
+----------------------------+----------------+
| cgu_instructions           | 10 bytes       |
+----------------------------+----------------+
| codegen_unit_size_estimate | 1642890 bytes  |
+----------------------------+----------------+
| dep_graph                  | 76384022 bytes |
+----------------------------+----------------+
| linked_artifact            | 55529472 bytes |
+----------------------------+----------------+
| object_file                | 1369 bytes     |
+----------------------------+----------------+
| query_cache                | 24984431 bytes |
+----------------------------+----------------+
| work_product_index         | 19515 bytes    |
+----------------------------+----------------+

After a file change I got:

summarize summarize app-0017256
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| Item                                                       | Self time | % of total time | Time     | Item count | Incremental load time | Incremental result hashing time |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| codegen_copy_artifacts_from_incr_cache                     | 4.85s     | 38.354          | 4.85s    | 254        | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| LLVM_passes                                                | 1.32s     | 10.479          | 1.32s    | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| LLVM_module_codegen_emit_obj                               | 1.26s     | 10.001          | 1.26s    | 3          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| finish_ongoing_codegen                                     | 1.06s     | 8.369           | 1.49s    | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| run_linker                                                 | 1.00s     | 7.940           | 1.00s    | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| copy_all_cgu_workproducts_to_incr_comp_cache_dir           | 436.24ms  | 3.453           | 436.24ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| codegen_module                                             | 258.80ms  | 2.048           | 721.24ms | 2          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_prepare_session_directory                        | 253.55ms  | 2.007           | 253.55ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| monomorphization_collector_graph_walk                      | 208.57ms  | 1.651           | 695.68ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_decode_entry_optimized_mir                        | 143.52ms  | 1.136           | 143.52ms | 5229       | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| cgu_partitioning_place_items                               | 119.49ms  | 0.946           | 149.95ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_encode_dep_graph                                 | 114.18ms  | 0.904           | 114.18ms | 1386779    | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| evaluate_obligation                                        | 93.74ms   | 0.742           | 104.57ms | 23392      | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| layout_of                                                  | 89.07ms   | 0.705           | 3.52s    | 67430      | 0.00ns                | 19.00µs                         |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| mir_shims                                                  | 88.60ms   | 0.701           | 134.71ms | 10669      | 0.00ns                | 89.60µs                         |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| items_of_instance                                          | 88.17ms   | 0.698           | 146.30ms | 3          | 85.78ms               | 25.30µs                         |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_load_dep_graph                                   | 67.26ms   | 0.532           | 67.26ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| typeck                                                     | 60.23ms   | 0.477           | 106.62ms | 15         | 1.03ms                | 160.20µs                        |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| LLVM_module_codegen                                        | 60.06ms   | 0.475           | 1.32s    | 3          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| assert_symbols_are_distinct                                | 57.30ms   | 0.454           | 102.72ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| codegen_crate                                              | 55.08ms   | 0.436           | 1.81s    | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| encode_query_results_for                                   | 53.58ms   | 0.424           | 53.58ms  | 61         | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| optimized_mir                                              | 52.39ms   | 0.415           | 196.12ms | 5229       | 2.66ms                | 48.61ms                         |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_register_crate                                    | 42.43ms   | 0.336           | 177.70ms | 280        | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_decode_entry_exported_symbols                     | 40.87ms   | 0.323           | 40.87ms  | 280        | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| normalize_canonicalized_projection_ty                      | 37.42ms   | 0.296           | 46.84ms  | 2150       | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| trait_impls_of                                             | 36.81ms   | 0.291           | 51.84ms  | 284        | 0.00ns                | 695.60µs                        |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| fn_abi_of_instance                                         | 35.05ms   | 0.277           | 280.31ms | 19748      | 0.00ns                | 1.40µs                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_serialize_result_cache                           | 35.01ms   | 0.277           | 88.63ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| symbol_name                                                | 33.61ms   | 0.266           | 34.51ms  | 766        | 30.08ms               | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| LLVM_module_optimize                                       | 22.65ms   | 0.179           | 22.65ms  | 3          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| find_cgu_reuse                                             | 22.30ms   | 0.176           | 39.32ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_finalize_session_directory                       | 18.97ms   | 0.150           | 18.97ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| codegen_select_candidate                                   | 18.84ms   | 0.149           | 21.61ms  | 3260       | 491.90µs              | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| cgu_partitioning_internalize_symbols                       | 16.91ms   | 0.134           | 16.91ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| link_binary                                                | 15.02ms   | 0.119           | 1.03s    | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| collect_and_partition_mono_items                           | 14.64ms   | 0.116           | 995.18ms | 1          | 0.00ns                | 5.29ms                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| incr_comp_query_cache_promotion                            | 14.36ms   | 0.114           | 18.45ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| size_estimate                                              | 13.93ms   | 0.110           | 13.93ms  | 1          | 13.92ms               | 600.00ns                        |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_decode_entry_type_of                              | 12.23ms   | 0.097           | 12.23ms  | 19397      | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| expand_crate                                               | 11.27ms   | 0.089           | 58.87ms  | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| metadata_decode_entry_mir_coroutine_witnesses              | 10.67ms   | 0.084           | 10.67ms  | 1972       | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| monomorphization_collector                                 | 10.56ms   | 0.084           | 706.47ms | 1          | 0.00ns                | 0.00ns                          |
+------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+

...others smaller removed here...

Total cpu time: 12.6354861s
+----------------------------+----------------+
| Item                       | Artifact Size  |
+----------------------------+----------------+
| cgu_instructions           | 188887 bytes   |
+----------------------------+----------------+
| codegen_unit_size_estimate | 1642890 bytes  |
+----------------------------+----------------+
| dep_graph                  | 77465766 bytes |
+----------------------------+----------------+
| linked_artifact            | 55529472 bytes |
+----------------------------+----------------+
| object_file                | 20610309 bytes |
+----------------------------+----------------+
| query_cache                | 25228403 bytes |
+----------------------------+----------------+
| work_product_index         | 19515 bytes    |
+----------------------------+----------------+

What the heck is codegen_copy_artifacts_from_incr_cache?

Can I reduce it's time?

I guess that’s the copying of artifacts from the incremental compilation cache[1]. Try disabling incremental compilation:

# Cargo.toml
[profile.dev]
incremental = false

Do you have a weird antivirus or something else that could be making the copying slow?


  1. for codegen ↩︎

Disabled antivirus. And I've posted both incremental and not compilation times.

Where? It's not in that last post, it's not in the OP. Did you miss actually posting the new times?

If you read carefully, there are two blocks of text.

I separated them with the phrase: "After a file change I got:"

The first build still has incremental compilation turned on, otherwise it would not generate the artifacts needed to speed up the second compilation.

I know there are two. I interpreted the first block as the profile from a cold build (right after a cargo clean) and the second as a hot build (just adding a line to app/src/main.rs (or lib.rs)).

If you didn’t change the incremental value in Cargo.toml, incremental compilation is still enabled for both builds.

"Incremental compilation" is not the feature where modifying one crate doesn't need to recompile its dependencies. Cargo always saves those artifacts (if you don't change compiler flags).

Incremental compilation is a feature that allows the compilation of one crate to be split into parts that the compiler can reuse.

If your main.rs has a mod foo and you change just main.rs, foo.rs is not recompiled thanks to incremental compilation.[1]


  1. the actual system is more complex than just splitting up source files, but that's the general idea of what incremental does ↩︎

Ok. I really don't know why.

What I'm trying to accomplish here is to detect why my incremental (edit, build, run cycle) is slow.

Thank you very much. Now it is clear.

Can you help me understand how to speed up the edit, build, run cycle?

I have this PC build right now: Part List - AMD Ryzen 9 9950X, Mars Gaming MCV4 ATX Mid Tower - PCPartPicker.

And Windows 11.