Repository: rust
Issue: Performance analysis on `aws-sdk-ec2`
Labels: S-experimental

I'm doing some performance analysis on the (long) compilation of the crate `aws-sdk-ec2`, and using this issue to take notes about it.

`rustc +nightly --version`: `rustc 1.81.0-nightly (0c81f94b9 2024-07-10)`

`cargo +nightly rustc -- -Ztime-passes`:

```
time:   0.000; rss:   47MB ->   48MB (   +0MB)	parse_crate
time:   0.000; rss:   49MB ->   49MB (   +1MB)	setup_global_ctxt
time:   0.000; rss:   51MB ->   51MB (   +0MB)	crate_injection
time:   1.680; rss:   51MB -> 1103MB (+1052MB)	expand_crate
time:   1.680; rss:   51MB -> 1103MB (+1052MB)	macro_expand_crate
time:   0.000; rss: 1103MB -> 1104MB (   +0MB)	maybe_building_test_harness
time:   0.052; rss: 1104MB -> 1103MB (   +0MB)	AST_validation
time:   0.007; rss: 1103MB -> 1106MB (   +3MB)	finalize_imports
time:   0.033; rss: 1106MB -> 1106MB (   +0MB)	compute_effective_visibilities
time:   0.034; rss: 1106MB -> 1108MB (   +2MB)	finalize_macro_resolutions
time:   0.969; rss: 1108MB -> 1366MB ( +257MB)	late_resolve_crate
time:   0.048; rss: 1366MB -> 1397MB (  +32MB)	resolve_check_unused
time:   0.064; rss: 1397MB -> 1397MB (   +0MB)	resolve_postprocess
time:   1.157; rss: 1103MB -> 1397MB ( +294MB)	resolve_crate
time:   0.043; rss: 1398MB -> 1398MB (   +0MB)	write_dep_info
time:   0.044; rss: 1398MB -> 1399MB (   +1MB)	complete_gated_feature_checking
time:   0.103; rss: 2151MB -> 2145MB (   -6MB)	drop_ast
time:   3.029; rss: 1398MB -> 1991MB ( +593MB)	looking_for_derive_registrar
time:   3.577; rss: 1398MB -> 2034MB ( +636MB)	misc_checking_1
time:   9.258; rss: 2034MB -> 2694MB ( +660MB)	coherence_checking
time:  18.136; rss: 2034MB -> 3353MB (+1319MB)	type_check_crate
time:  14.660; rss: 3353MB -> 4533MB (+1181MB)	MIR_borrow_checking
time:   4.442; rss: 4533MB -> 4807MB ( +273MB)	MIR_effect_checking
time:   0.421; rss: 4843MB -> 4845MB (   +2MB)	module_lints
time:   0.421; rss: 4843MB -> 4845MB (   +2MB)	lint_checking
time:   0.453; rss: 4845MB -> 4845MB (   +0MB)	privacy_checking_modules
time:   0.135; rss: 4845MB -> 4849MB (   +4MB)	check_lint_expectations
time:   1.725; rss: 4811MB -> 4849MB (  +38MB)	misc_checking_3
time:   0.044; rss: 5120MB -> 5120MB (   +0MB)	monomorphization_collector_root_collections
time:   6.002; rss: 5120MB -> 5595MB ( +476MB)	monomorphization_collector_graph_walk
time:   2.506; rss: 5589MB -> 5702MB ( +113MB)	partition_and_assert_distinct_symbols
time:  10.513; rss: 4849MB -> 5546MB ( +697MB)	generate_crate_metadata
time:  28.231; rss: 5554MB -> 6196MB ( +642MB)	codegen_to_LLVM_IR
time:  28.440; rss: 5546MB -> 6196MB ( +649MB)	codegen_crate
time:  26.305; rss: 5947MB -> 6209MB ( +261MB)	LLVM_passes
time:   0.865; rss: 6196MB -> 6257MB (  +61MB)	encode_query_results
time:   0.967; rss: 6196MB -> 6167MB (  -28MB)	incr_comp_serialize_result_cache
time:   0.967; rss: 6196MB -> 6167MB (  -28MB)	incr_comp_persist_result_cache
time:   0.968; rss: 6196MB -> 6167MB (  -28MB)	serialize_dep_graph
time:   0.298; rss: 6167MB -> 4211MB (-1957MB)	free_global_ctxt
time:   0.520; rss: 3789MB -> 3893MB ( +104MB)	link_rlib
time:   0.527; rss: 3789MB -> 3893MB ( +104MB)	link_binary
time:   0.544; rss: 3789MB -> 3484MB ( -305MB)	link_crate
time:   0.546; rss: 4211MB -> 3484MB ( -727MB)	link
time:  86.838; rss:   32MB ->  245MB ( +213MB)	total
```

<details><summary>Optimized version, for reference</summary>

`cargo +nightly rustc -- -C opt-level=3 -Ztime-passes`:

```
time:   0.000; rss:   47MB ->   47MB (   +0MB)	parse_crate
time:   0.000; rss:   48MB ->   49MB (   +1MB)	setup_global_ctxt
time:   0.000; rss:   51MB ->   51MB (   +0MB)	crate_injection
time:   1.788; rss:   51MB -> 1104MB (+1052MB)	expand_crate
time:   1.788; rss:   51MB -> 1104MB (+1053MB)	macro_expand_crate
time:   0.000; rss: 1104MB -> 1104MB (   +0MB)	maybe_building_test_harness
time:   0.048; rss: 1104MB -> 1104MB (   +0MB)	AST_validation
time:   0.006; rss: 1104MB -> 1106MB (   +2MB)	finalize_imports
time:   0.027; rss: 1106MB -> 1106MB (   +0MB)	compute_effective_visibilities
time:   0.034; rss: 1106MB -> 1108MB (   +2MB)	finalize_macro_resolutions
time:   0.975; rss: 1108MB -> 1366MB ( +258MB)	late_resolve_crate
time:   0.041; rss: 1366MB -> 1398MB (  +32MB)	resolve_check_unused
time:   0.059; rss: 1398MB -> 1398MB (   +0MB)	resolve_postprocess
time:   1.142; rss: 1104MB -> 1398MB ( +294MB)	resolve_crate
time:   0.032; rss: 1400MB -> 1399MB (   -1MB)	write_dep_info
time:   0.030; rss: 1399MB -> 1399MB (   +1MB)	complete_gated_feature_checking
time:   0.103; rss: 2153MB -> 2148MB (   -6MB)	drop_ast
time:   3.136; rss: 1399MB -> 1994MB ( +595MB)	looking_for_derive_registrar
time:   3.674; rss: 1399MB -> 2036MB ( +638MB)	misc_checking_1
time:   9.398; rss: 2036MB -> 2696MB ( +660MB)	coherence_checking
time:  18.398; rss: 2036MB -> 3354MB (+1318MB)	type_check_crate
time:  14.451; rss: 3354MB -> 4534MB (+1180MB)	MIR_borrow_checking
time:   4.738; rss: 4534MB -> 4803MB ( +269MB)	MIR_effect_checking
time:   0.421; rss: 4835MB -> 4840MB (   +4MB)	module_lints
time:   0.421; rss: 4835MB -> 4840MB (   +4MB)	lint_checking
time:   0.454; rss: 4840MB -> 4840MB (   +0MB)	privacy_checking_modules
time:   0.136; rss: 4840MB -> 4844MB (   +4MB)	check_lint_expectations
time:   1.728; rss: 4807MB -> 4844MB (  +37MB)	misc_checking_3
time:   2.511; rss: 4844MB -> 5017MB ( +173MB)	generate_crate_metadata
time:   0.049; rss: 5017MB -> 5017MB (   +0MB)	monomorphization_collector_root_collections
time:   8.685; rss: 5017MB -> 5424MB ( +406MB)	monomorphization_collector_graph_walk
time:   4.531; rss: 5417MB -> 5539MB ( +122MB)	partition_and_assert_distinct_symbols
time:  53.323; rss: 5467MB -> 7019MB (+1553MB)	codegen_to_LLVM_IR
time:  66.963; rss: 5017MB -> 7019MB (+2002MB)	codegen_crate
time:   1.174; rss: 7019MB -> 7138MB ( +119MB)	encode_query_results
time:   1.298; rss: 7019MB -> 7071MB (  +52MB)	incr_comp_serialize_result_cache
time:   1.298; rss: 7019MB -> 7071MB (  +52MB)	incr_comp_persist_result_cache
time:   1.298; rss: 7019MB -> 7071MB (  +52MB)	serialize_dep_graph
time:   0.339; rss: 7071MB -> 5014MB (-2057MB)	free_global_ctxt
time: 214.199; rss: 5916MB -> 4364MB (-1552MB)	LLVM_passes
time:   0.001; rss: 1415MB -> 1352MB (  -63MB)	join_worker_thread
time: 161.500; rss: 5014MB -> 1352MB (-3662MB)	finish_ongoing_codegen
time:   0.569; rss:  931MB -> 1054MB ( +123MB)	link_rlib
time:   0.576; rss:  931MB -> 1054MB ( +123MB)	link_binary
time:   0.580; rss:  931MB ->  935MB (   +4MB)	link_crate
time: 162.082; rss: 5014MB ->  935MB (-4079MB)	link
time: 279.744; rss:   32MB ->  365MB ( +333MB)	total
```

</details>