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

Compile Slow #4082

Open
Adancurusul opened this issue Dec 5, 2023 · 11 comments
Open

Compile Slow #4082

Adancurusul opened this issue Dec 5, 2023 · 11 comments
Labels
a:language-rust Rust API and codegen (mO,mS) optimization

Comments

@Adancurusul
Copy link

Whether in linux or windows.
rust is very slow at the end of the compilation
Even if I don't modify any files he still takes more than 2 minutes
The following two graphs show the output of the compilation in linux without changing the code.
1a8001861f698e10b7870225e82494d
f8136598a8d7f4dc2c988e6d3babedd
Here are two screenshots of the output using --timings
image
fb92ef9ad2c76a5bf564056ec98ca29

This slows down my development.
Is this due to a problem with my code?I can provide my source code if needed.

@Adancurusul
Copy link
Author

Here is the code : https://github.com/Adancurusul/slint_bug

@hunger
Copy link
Member

hunger commented Dec 5, 2023

Slint does generate a lot of code, especially when embedding resources, which can take long to process.

For me it is 19s in the build script and 45s in the build itself.

@hunger
Copy link
Member

hunger commented Dec 5, 2023

rustc self-profile from the above project (anything above 1% of time, there is a log tail of functions below this still):

139➜  summarize summarize hot_cold_plate-0643622.mm_profdata
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| Item                                                                    | Self time | % of total time | Time     | Item count | Incremental load time | Incremental result hashing time |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| live_symbols_and_ignored_derived_traits                                 | 20.42s    | 29.497          | 20.71s   | 1          | 0.00ns                | 1.50ms                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| LLVM_module_codegen_emit_obj                                            | 13.68s    | 19.759          | 13.68s   | 3          | 0.00ns                | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| LLVM_passes                                                             | 9.20s     | 13.288          | 9.20s    | 1          | 0.00ns                | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| finish_ongoing_codegen                                                  | 5.68s     | 8.208           | 5.69s    | 1          | 0.00ns                | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| expand_crate                                                            | 2.57s     | 3.707           | 3.01s    | 1          | 0.00ns                | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| early_lint_checks                                                       | 2.24s     | 3.235           | 2.28s    | 1          | 0.00ns                | 1.53µs                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| codegen_module                                                          | 2.01s     | 2.898           | 2.45s    | 2          | 0.00ns                | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| run_linker                                                              | 1.45s     | 2.097           | 1.45s    | 1          | 0.00ns                | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| monomorphization_collector_graph_walk                                   | 1.29s     | 1.861           | 2.64s    | 1          | 0.00ns                | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| hir_crate                                                               | 936.88ms  | 1.353           | 3.34s    | 1          | 0.00ns                | 1.57µs                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
| late_resolve_crate                                                      | 750.38ms  | 1.084           | 751.23ms | 1          | 0.00ns                | 0.00ns                          |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+

@hunger hunger added a:compiler Slint compiler internal (not the codegen, not the parser) enhancement New feature or request labels Dec 5, 2023
@Adancurusul
Copy link
Author

That's weird, what CPU are you using.
I'm using an AMD 5800u laptop and a 5900X desktop. Both tests came back with this effect. My friend with an intel CPU tests the build time to be much shorter.
And the screenshots I've taken are from code I haven't changed, so theoretically it shouldn't take too long to compile. Moreover, the CPU usage is very low during the compilation process. This is very confusing to me.

@hunger
Copy link
Member

hunger commented Dec 6, 2023

I have a "AMD Ryzen 9 3900X 12-Core Processor" according to /proc/cpuinfo.

@qarmin
Copy link

qarmin commented Dec 9, 2023

With my app, adding space at the end of slint file takes 33seconds(7 build script, 26 second rest) - i7 4770 - 4/8 HT
But I use by default mold linker which should be faster than llvm linker - https://github.com/rui314/mold

Also I use cranelift - https://github.com/rust-lang/rustc_codegen_cranelift which decrease time to compile entire project from 7 minutes to 2m 30s

cargo build

become

CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend

@ogoffart ogoffart added a:language-rust Rust API and codegen (mO,mS) optimization and removed a:compiler Slint compiler internal (not the codegen, not the parser) enhancement New feature or request labels Jan 22, 2024
@qarmin
Copy link

qarmin commented Feb 20, 2024

I'm not sure why I didn't notice this before(I don't think it occurred before), but building an application in release mode takes now over 87 minutes, of which it takes about 83 minutes to compile my application.
In debug mode, the whole thing(which also means compiling all dependencies) takes 8 minutes, which is not a big problem.

Cargo timings

@qarmin
Copy link

qarmin commented Feb 20, 2024

rust-lang/rust#121354 (comment)

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

@ogoffart
Copy link
Member

Slint 1.7 contains some optimization that reduce a bit the size of the generated code and that helps a bit with the compilation time.

@Adancurusul
Copy link
Author

Adancurusul commented Jul 31, 2024

It is indeed much faster than 1.5
Here is a comparison of the compilation of an old project
cargo run -r --timings

  • before (1.5
    img_v3_02cr_ae28ab4d-effa-4eaa-9607-7aee5fdee88g
    img_v3_02cr_1208dcc1-abae-45dc-81a1-0c65cd4dc3dg
  • after using 1.7
    img_v3_02da_bf753c9f-3d6b-4933-b426-7e7fae6aa08g
    img_v3_02da_ee4e1f99-9374-45c8-b212-db09f860d12g

Thanks a lot!

@ilmai
Copy link

ilmai commented Aug 18, 2024

I'm also encountering slow builds with slint although I'm now on 1.7. The part that's slow seems to be different for me though. Presumably slint is generating so many generic types that it's causing the slowdown?

time:   0.001; rss:   34MB ->   35MB (   +1MB)  parse_crate
time:   0.000; rss:   35MB ->   35MB (   +0MB)  incr_comp_prepare_session_directory
time:   0.000; rss:   35MB ->   35MB (   +0MB)  incr_comp_garbage_collect_session_directories
time:   0.000; rss:   35MB ->   37MB (   +1MB)  setup_global_ctxt
time:   0.000; rss:   38MB ->   38MB (   +0MB)  crate_injection
time:   1.004; rss:   38MB ->  314MB ( +276MB)  expand_crate
time:   1.004; rss:   38MB ->  314MB ( +276MB)  macro_expand_crate
time:   0.009; rss:  314MB ->  314MB (   +0MB)  AST_validation
time:   0.001; rss:  314MB ->  314MB (   +0MB)  finalize_imports
time:   0.000; rss:  314MB ->  314MB (   +0MB)  compute_effective_visibilities
time:   0.002; rss:  314MB ->  315MB (   +0MB)  finalize_macro_resolutions
time:   0.165; rss:  315MB ->  377MB (  +63MB)  late_resolve_crate
time:   0.006; rss:  377MB ->  377MB (   +0MB)  resolve_check_unused
time:   0.000; rss:  377MB ->  377MB (   +0MB)  resolve_report_errors
time:   0.010; rss:  377MB ->  377MB (   +0MB)  resolve_postprocess
time:   0.184; rss:  314MB ->  377MB (  +63MB)  resolve_crate
time:   0.006; rss:  377MB ->  378MB (   +0MB)  write_dep_info
time:   0.000; rss:  378MB ->  378MB (   +0MB)  looking_for_entry_point
time:   0.006; rss:  378MB ->  378MB (   +0MB)  complete_gated_feature_checking
time:   0.040; rss:  496MB ->  496MB (   +0MB)  drop_ast
time:   0.372; rss:  378MB ->  458MB (  +80MB)  looking_for_derive_registrar
time:   0.000; rss:  459MB ->  459MB (   +0MB)  unused_lib_feature_checking
time:   0.430; rss:  378MB ->  459MB (  +81MB)  misc_checking_1
time:   0.289; rss:  459MB ->  509MB (  +50MB)  coherence_checking
time:   8.659; rss:  459MB ->  793MB ( +334MB)  type_check_crate
time:   3.279; rss:  793MB -> 1102MB ( +309MB)  MIR_borrow_checking
time:   1.486; rss: 1102MB -> 1138MB (  +36MB)  MIR_effect_checking
time:   0.000; rss: 1138MB -> 1138MB (   +0MB)  layout_testing
time:   0.060; rss: 1138MB -> 1139MB (   +1MB)  module_lints
time:   0.060; rss: 1138MB -> 1139MB (   +1MB)  lint_checking
time:   0.105; rss: 1139MB -> 1139MB (   +0MB)  privacy_checking_modules
time:   0.021; rss: 1139MB -> 1139MB (   +0MB)  check_lint_expectations
time:   0.228; rss: 1138MB -> 1139MB (   +2MB)  misc_checking_3
time:   0.002; rss: 1149MB -> 1149MB (   +0MB)  monomorphization_collector_root_collections
time: 713.696; rss: 1149MB -> 1849MB ( +700MB)  monomorphization_collector_graph_walk
time:   0.201; rss: 1851MB -> 1901MB (  +49MB)  partition_and_assert_distinct_symbols
time: 714.083; rss: 1139MB -> 1906MB ( +767MB)  generate_crate_metadata
time:   0.000; rss: 1912MB -> 1913MB (   +1MB)  write_allocator_module
time:   0.000; rss: 1913MB -> 1914MB (   +0MB)  find_cgu_reuse
time:   3.662; rss: 1914MB -> 2514MB ( +600MB)  codegen_to_LLVM_IR
time:   3.680; rss: 1906MB -> 2514MB ( +607MB)  codegen_crate
time:   0.000; rss: 2514MB -> 2514MB (   +0MB)  assert_dep_graph
time:   0.000; rss: 2514MB -> 2514MB (   +0MB)  incr_comp_persist_dep_graph
time:   0.200; rss: 2515MB -> 2615MB ( +100MB)  encode_query_results
time:   0.241; rss: 2515MB -> 2608MB (  +93MB)  incr_comp_serialize_result_cache
time:   0.241; rss: 2514MB -> 2608MB (  +94MB)  incr_comp_persist_result_cache
time:   0.242; rss: 2514MB -> 2608MB (  +94MB)  serialize_dep_graph
time:   0.098; rss: 2608MB -> 1601MB (-1007MB)  free_global_ctxt
time:  26.615; rss: 2120MB -> 2248MB ( +128MB)  LLVM_passes
time:   0.001; rss: 2192MB -> 2137MB (  -55MB)  join_worker_thread
time:   0.046; rss: 2137MB -> 1421MB ( -717MB)  copy_all_cgu_workproducts_to_incr_comp_cache_dir
time:  23.429; rss: 1601MB -> 1421MB ( -180MB)  finish_ongoing_codegen
time:   0.000; rss: 1421MB -> 1421MB (   +0MB)  serialize_work_products
time:   0.000; rss: 1352MB -> 1352MB (   +0MB)  incr_comp_finalize_session_directory
time:   0.270; rss: 1353MB -> 1353MB (   +0MB)  run_linker
time:   0.060; rss: 1353MB -> 1365MB (  +11MB)  link_rlib
time:   0.340; rss: 1352MB -> 1365MB (  +13MB)  link_binary
time:   0.343; rss: 1352MB -> 1328MB (  -24MB)  link_crate
time:  23.774; rss: 1601MB -> 1328MB ( -272MB)  link
time: 757.210; rss:   20MB ->  215MB ( +195MB)  total

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) optimization
Projects
None yet
Development

No branches or pull requests

5 participants