Discussion: Compilation times and the TUI crate monolith — are others feeling this?
Context
I've been working on the custom slash command refactoring (Layers 5, 5.1, 5.2 — the dispatch precedence and user-command registry work). As part of that, I'm spending a lot of time waiting for compiles, and I wanted to open a discussion to see if others share this experience.
The Numbers
The workspace has 18 crates. One of them — codewhale-tui — accounts for:
- 476,336 lines of Rust (82% of the entire workspace)
- 588 source files in a single crate
- Release build with
lto = trueandcodegen-units = 1: 8–16 minutes - Full test suite (
cargo test --workspace): 30+ minutes
A single-line change to a command handler or a typo fix in any file under crates/tui/src/ triggers a recompilation of the entire 476k-line crate. The other 17 crates combined (~97k lines) compile once and cache just fine — they're not the bottleneck.
The Impact
On my development machine and GitHub Actions CI, this means:
- I can only afford 2–3 compile-test iterations per hour
- A 5-minute distraction during a build costs another 10+ minutes to recompile
- CI minutes burn quickly on every push, even for trivial changes
- The feedback loop discourages small, incremental refactoring — you batch everything into one big change to minimize compiles
What I'm Doing About It
I'm incrementally extracting the commands/ module (~39k lines, 87 files) into a separate codewhale-commands crate with a CommandContext trait interface to decouple it from the TUI's App struct. The goal is that changing a command file recompiles only that crate (~5 seconds) instead of the entire TUI.
Longer-term, I see several modules inside crates/tui/src/ that have sibling workspace crates already:
| TUI Module | Lines | Sibling Crate |
|---|---|---|
tools/ |
103k | crates/tools |
config/ |
11k | crates/config |
hooks/ |
7k | crates/hooks |
execpolicy/ |
1k | crates/execpolicy |
mcp/ |
8k | crates/mcp |
Consolidating these would be a natural follow-up.
The Question
Is this a pain others are feeling too? How are you handling the compilation times?
- Are you using
cargo checkfor most iterations and only doing full builds before PR? - Do you have local tooling (mold, sccache, custom profiles) that helps?
- Has the team discussed splitting the TUI crate before?
- Are there plans or work-in-progress for this upstream?
I'm happy to contribute the commands extraction back if there's interest. I'd also love to hear if there are patterns or approaches I'm missing that could make this better for everyone.
Signed-off by: Paulo Aboim Pinto
Oh, finally someone who shares my pain! Waiting for compiles is quite suffering but I've never dared to touch it because I thought this is a big project and I might mess things up. If you can improve this, it would help us a lot!!
yes - I am feeling it big time too ........ Crate consolidation is absolutely a goal. Any contribution toward this direction will be a huge huge help!!!
I'm glad this pain is not mine only ... I believe that reducing the size of the files ... and we have monolithic files, and breaking them down into logical crates will help ... I will keep working on that...
Thanks for putting real numbers on this — the 82%-of-workspace measurement and the observation that the other 17 crates "compile once and cache just fine" match exactly what we measured while triaging this today (now 682,959 lines / 620 files, 86% of the workspace; a warm incremental release rebuild of codewhale-tui after touching one file took 13m 57s on a 14-core M-series).
Status: build time is now a first-class lane for v0.9.5. We just filed an epic plus four agent-ready sub-issues, and the executing agents have explicit authority to rewrite what's in the way:
- #5249 — v0.9.5 build-time epic (measurement baseline + the phases below)
- #5245 — stop the full tui+cli rebuild that currently happens on every local
git commit(the build-SHA stamp watches the branch ref — this is likely part of why your iteration count per hour is so low) - #5246 — move fat-LTO/
codegen-units=1to adistprofile for shipped artifacts; the local--releasegate becomes thin-LTO - #5248 — dependency-graph diet (708 packages, 10 duplicate-version deps, redundant HTTP/HTML stacks)
- #5247 — consolidate the 25 integration-test binaries in
crates/tui/tests/
On your questions: yes, cargo check for iteration is what most of us do; profiles and the commit-stamp fix above are the near-term relief; and the crate split has been discussed and sequenced in #3306 (structural decomposition: #3948, #3950, #3925, #4747).
Your commands/ extraction (~40k lines) is very welcome — it slots into phase 5 of the epic. Two asks so it lands smoothly: build it against current main following the #3306 rule that code-motion PRs carry no behavior changes, and record before/after incremental-build timing for a command-file edit in the PR body (the epic makes that timing evidence the standard for every extraction).
Verified shipped on main during 0.9.12 triage. Evidence: Superseded by the build-time epics #5249/#5316; crate split and build lanes are tracked there.