Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very slow 80 minutes release build, due mir_pass_scalar_replacement_of_aggregates (sroa) optimization enabled #121354

Open
qarmin opened this issue Feb 20, 2024 · 1 comment
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@qarmin
Copy link

qarmin commented Feb 20, 2024

When compiling recently project with release flag - cargo build --release I found that compilation takes more than 80 minutes. Debug build completes in ~8 minutes which is acceptable for me.

Cargo timing results:
debug - debug_cargo-timing-20240220T105545Z.html.zip
release - release_cargo-timing-20240220T110513Z.html.zip

Later I run RUSTFLAGS="-Zself-profile" cargo +nightly rustc --release and I got this results

+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| Item                                                                    | Self time | % of total time | Time     | Item count |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| mir_pass_scalar_replacement_of_aggregates                               | 4933.25s  | 96.338          | 4933.25s | 4860       |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| LLVM_module_optimize                                                    | 35.17s    | 0.687           | 35.17s   | 17         |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| LLVM_passes                                                             | 34.53s    | 0.674           | 34.58s   | 1          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| LLVM_lto_optimize                                                       | 34.15s    | 0.667           | 34.15s   | 16         |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| finish_ongoing_codegen                                                  | 30.40s    | 0.594           | 30.40s   | 1          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| LLVM_module_codegen_emit_obj                                            | 28.04s    | 0.548           | 28.04s   | 17         |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| typeck                                                                  | 3.45s     | 0.067           | 3.60s    | 5318       |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| codegen_crate                                                           | 2.25s     | 0.044           | 4942.10s | 1          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+
| LLVM_thin_lto_import                                                    | 2.05s     | 0.040           | 2.05s    | 16         |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+

this is output from RUSTFLAGS="-Zself-profile" cargo +nightly rustc

+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| Item                                                                    | Self time | % of total time | Time     | Item count | Incremental result hashing time |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| LLVM_module_codegen_emit_obj                                            | 28.48s    | 32.021          | 28.48s   | 257        | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| run_linker                                                              | 19.26s    | 21.659          | 19.26s   | 1          | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| LLVM_passes                                                             | 9.83s     | 11.050          | 9.83s    | 1          | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| typeck                                                                  | 6.91s     | 7.765           | 7.28s    | 5318       | 2.89s                           |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| codegen_module                                                          | 6.39s     | 7.183           | 10.44s   | 256        | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| mir_borrowck                                                            | 1.76s     | 1.979           | 3.30s    | 5318       | 1.93ms                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| LLVM_module_codegen                                                     | 1.37s     | 1.544           | 29.85s   | 257        | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| incr_comp_encode_dep_graph                                              | 1.36s     | 1.525           | 1.36s    | 1156568    | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| metadata_decode_entry_associated_item                                   | 1.00s     | 1.130           | 1.00s    | 5643       | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+
| eval_to_allocation_raw                                                  | 925.25ms  | 1.040           | 1.24s    | 16774      | 10.06ms                         |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+

During compilation, Slint generates single rust file with 90000 lines - main_window.rs.zip

repo - https://github.com/qarmin/czkawka/tree/7.0.0/krokiet

git clone https://github.com/qarmin/czkawka.git
cd czkawka/krokiet
time cargo build
time cargo build --release

Meta

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
System:
  Host: rafal-komputer Kernel: 6.5.0-15-generic arch: x86_64 bits: 64
    Desktop: GNOME v: 45.2 Distro: Ubuntu 23.10 (Mantic Minotaur)
CPU:
  Info: quad core model: Intel Core i7-4770 bits: 64 type: MT MCP cache:
    L2: 1024 KiB
  Speed (MHz): avg: 3691 min/max: 800/3900 cores: 1: 3691 2: 3691 3: 3691
    4: 3691 5: 3691 6: 3691 7: 3691 8: 3691
@qarmin qarmin added the C-bug Category: This is a bug. label Feb 20, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 20, 2024
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-mir-opt Area: MIR optimizations and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 20, 2024
@matthiaskrgr matthiaskrgr added the I-compiletime Issue: Problems and improvements with respect to compile times. label Feb 20, 2024
@Noratrieb
Copy link
Member

https://gist.github.com/Nilstrieb/b3ec10b0408b75bfc5d68a3871d3d230
This is one of the files that slint helpfully generates for us for the main_window file, I assume.
I.. certainly don't blame SROA (which "ungroups" local variable structs into one local variable for every field) for being pathologically slow here.... that is.. a whole very lot of fields..
The fix here probably is to make SROA stop after some number of operations, to stop it from running off and turning this enormous mess into some rainbow wonderland where everything is a local variable after 80 minutes.

But there's also something pretty weird with the code. This struct has dozens of thousands of nested fields and a size of 241KB, which seems.. fun. Never having used slint, your source code looks reasonable to me, but slint generates quite a monstrosity from it...
In the meantime, you can use -Zmir-enable-passes=-ScalarReplacementOfAggregates on the nightly compiler to disable this pass (though the compile times are still pretty bad, understandably).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants