[bug] Tauri 2.0 compiles much slower than version 1.0. How can I configure it to improve compilation speed?
Describe the bug
[profile.dev] incremental = true # 以较小的步骤编译您的二进制文件。
[profile.release]
codegen-units = 1 # 允许 LLVM 执行更好的优化。
lto = true # 启用链接时优化。
opt-level = "s" # 优先考虑小的二进制文件大小。如果您更喜欢速度,请使用 3。
panic = "abort" # 通过禁用 panic 处理程序来提高性能。
strip = true # 确保移除调试符号。
The compilation speed remains slow regardless of whether the above configurations are applied or not. Tauri 2.0 takes 1 minute and 10 seconds to compile, while version 1.0 completes in under 20 seconds. How can I improve the compilation time for version 2.0?
Reproduction
No response
Expected behavior
No response
Full tauri info output
Tauri 2.0 takes 1 minute and 10 seconds to compile, while version 1.0 completes in under 20 seconds.
Stack trace
Additional context
No response
Please include the output of the tauri info command as required by the issue template.
Are we talking about tauri build, tauri build --debug or tauri dev ? Do your v1 and v2 apps have similar features and dependencies?
Please include the output of the
tauri infocommand as required by the issue template.Are we talking about
tauri build,tauri build --debugortauri dev? Do your v1 and v2 apps have similar features and dependencies?
Yes, v1 and v2 are the same code, but the Rust versions are different. v1 is 1.76, while v2 is 1.77.2.
Not entirely sure how I much I could do, but I'll try to dig into this a little bit, the long compile time has been bothering me as well for quite some time now
I'm on MacOS (w/ a super fast Mac Studio M4) and using VS-Code w/ rust-analyzer. I just switched an app I'm working on to V2. I also experienced an order of magnitude slower compilation time when running tauri dev.
After some observation, I noticed issues with rust-analyzer blocking. I also noticed that certain dependencies were getting recompiled nu-necessarily.
These two VSCode settings:
"rust-analyzer.cargo.targetDir": true,
"rust-analyzer.cargo.extraEnv": {
"MACOSX_DEPLOYMENT_TARGET": "10.13"
}
and this in tauri.conf.json
"bundle": {
"macOS": {
"minimumSystemVersion": "10.13"
}
}
Solved it. Now when I make a change to the rust code, the recompilation is nearly instant.
Courtesy of: https://yuexun.me/how-to-make-your-tauri-dev-faster/
This should apply to v1 as well though so almost off-topic. Thanks for sharing though.
Fair point! Indeed these settings apply regardless of tauri version. In my case, when my app was using tauri V1, compilation was fast enough that I didn't really recognize that it could have been improved. For some reason, when moving to tauri V2, I ran into this slow compile time issue on the first compilation, so it became IMMEDIATELY noticeable. This was definitely NOT tauri's "fault" really, it feels a little bit coincidental? But what tipped me off was
Compiling objc2-cloud-kit v0.3.1
Compiling objc2-core-data v0.3.1
Compiling objc2-core-image v0.3.1
Compiling objc2-app-kit v0.3.1
Compiling objc2-web-kit v0.3.1
happened for me with every single change I made to the rust code, and taking 10 to 15 seconds each time, no matter how trivial the change. And at the same time, rust-analyzer was trying to do its thing too, and so the reads and writes to the target dir were competing for system resources. I wasn't paying too much attention to what tauri v1 was compiling, it just sort of felt like tauri v2 was compiling a lot more stuff - which seemed plausible to me because, well, it's a different version with presumably more features.
I just wanted to make sure people could find a way to solve non-tauri related compile time issues before chalking it up to some sort of issue with tauri itself.
Maybe there could be a section in the quick start guide about tooling settings to enable faster compiles? I think VSCode w/ rust-analyzer is a pretty common setup for people. Might be worth mentioning these settings for people like me who didn't even know about them until they started digging.
this isn't really something you should worry about, imo we should not set the deployment target in development. But yeah, this is tracked in https://github.com/tauri-apps/tauri/issues/11577