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

Compilation of the generated rust files by slint, due to their structure, can take up to several hours #4670

Open
qarmin opened this issue Feb 22, 2024 · 0 comments
Labels
a:language-rust Rust API and codegen (mO,mS) bug Something isn't working

Comments

@qarmin
Copy link

qarmin commented Feb 22, 2024

Issue reported also here rust-lang/rust#121354 - I also copied it here, because looks that this can be fixed by changing structure of slint files(but not sure if this is possible)

Copied content

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

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

@tronical tronical added bug Something isn't working a:language-rust Rust API and codegen (mO,mS) labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-rust Rust API and codegen (mO,mS) bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants