tauri
tauri copied to clipboard
[bug] Extremely long compilation times of the final binary crate
Describe the bug
While compiling a Tauri app, a lot of time[^1] is spent compiling the final binary. This also applies for hot/incremental builds using yarn tauri build
(including ones with no real changes to the code, like white space changes), with several users reporting compilation times also taking up to several minutes.
When profiling rustc (using RUSTC_BOOTSTRAP=1 cargo rustc -p theseus_gui -- -Z self-profile -Z self-profile-events=default,args
), I noticed that most of the compilation time is spend compiling #[tauri::command]
macros, in codegen_select_candidate
(~52% of compile time). Most of the queries seem related to tauri::InvokeResolver::respond_async_serialized
and tokio::runtime::task::harness
.
More notably, almost half of the compilation time is spent compiling two small functions in the (barely 19 LOC long!) pack.rs
file.
Attached is a Chrome Profiler file, converted from the original ~600MB .mm_profdata file using crox, with the minimum duration of 1ms: chrome_profiler-gui.zip[^2]
[^1]: Up to 10 minutes when compiling the binary itself, with dependencies precompiled to reduce noise.
[^2]: Can recommend ui.perfetto.dev for inspecting the file.
Reproduction
I could use some help isolating the issue to a minimal reproduction example, primarily because I'm not entirely sure what is the real cause of the compilation issues. In the meantime, I invite you to take a look at pack.rs in the Theseus project.
Expected behavior
No response
Platform and versions
Environment
› OS: Red Hat Enterprise Linux 9.2.0 X64 (EDITOR'S NOTE: It's actually AlmaLinux... which is basically RHEL. Reproducible by other users on different platforms.)
› Node.js: 20.2.0
› npm: 9.6.7
› pnpm: Not installed!
› yarn: 1.22.19
› rustup: 1.26.0
› rustc: 1.69.0
› cargo: 1.69.0
› Rust toolchain: stable-x86_64-unknown-linux-gnu
Packages
› @tauri-apps/cli [NPM]: 1.2.3
› @tauri-apps/api [NPM]: 1.2.0
› tauri [RUST]: 1.2.4,
› tauri-build [RUST]: 1.2.1,
› tao [RUST]: 0.15.8,
› wry [RUST]: 0.23.4,
App
› build-type: bundle
› CSP: default-src 'self'; connect-src https://modrinth.com https://*.modrinth.com; font-src https://cdn-raw.modrinth.com/fonts/inter/; img-src tauri: https: data: blob: 'unsafe-inline' asset: https://asset.localhost
› distDir: ../dist
› devPath: http://localhost:1420/
› framework: Vue.js
› bundler: Rollup
App directory structure
├─ .vscode
├─ src-tauri
├─ src
├─ node_modules
└─ dist
Stack trace
Example `codegen_select_candidate` argument (took 3s 931ms 854us):
(ParamEnv { caller_bounds: [], reveal: All, constness: NotConst }, Binder(<std::panic::AssertUnwindSafe<[closure@tokio::runtime::task::harness::poll_future<std::pin::Pin<std::boxed::Box<[async block@tauri::InvokeResolver::respond_async_serialized<[async block@theseus_gui/src-tauri/src/api/pack.rs:5:1: 5:18]>::{closure#0}]>>, std::sync::Arc<tokio::runtime::scheduler::multi_thread::handle::Handle>>::{closure#1}]> as std::ops::FnOnce<()>>, []))
Additional context
See: https://discord.com/channels/616186924390023171/1110350612345917532 (links to Tauri Discord server)
Credits to @Geometrically for the initial investigation.
cc @chippers, I think you might be interested in this
https://github.com/thesuzerain/tauri-compilation-slow-example
I have a more specific recreation of this. It should be easier to recreate