slint
slint copied to clipboard
Compile Slow
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.
Here are two screenshots of the output using --timings
This slows down my development. Is this due to a problem with my code?I can provide my source code if needed.
Here is the code : https://github.com/Adancurusul/slint_bug
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.
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 |
+-------------------------------------------------------------------------+-----------+-----------------+----------+------------+-----------------------+---------------------------------+
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.
I have a "AMD Ryzen 9 3900X 12-Core Processor" according to /proc/cpuinfo.
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
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
https://github.com/rust-lang/rust/issues/121354#issuecomment-1955037792
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).
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.
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
- after using 1.7
Thanks a lot!