Skip to content

perf(build): skip unnecessary work and reclaim Vite caches - #29479

Merged
OrcaWin merged 2 commits into
mainfrom
OrcaWin/remove-build-overhead
Oct 16, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
OrcaWin/remove-build-overhead

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

Ordinary dev and build commands skip unnecessary work automatically. Development main-process compilation uses less memory, and agents sharing a dependency install stop invalidating each other’s Vite cache.

What Changed

  • Skip main-process minification in development. Production minification and source-map settings keep their existing behavior, including the existing development source-map override.
  • Load the TypeScript JavaScript API only when the process-host plugin starts watching. Production config loading no longer pays for an unused compiler API.
  • Put desktop and web dependency caches in separate worktree-local directories, ignore them in Git, and exclude them from packaged apps.
  • Include those caches in pnpm reclaim-space: preview or remove tracked caches unused for 30 days. Dev servers record their use and process ownership; cleanup retains active, recent, foreign-host, and unverifiable caches. Startup and cleanup use the same short maintenance lock, without a persistent heartbeat.
  • Stop calculating gzip sizes solely for renderer/web build logs.

Why

These changes remove work from existing commands. Lazy loading preserves TypeScript’s configuration parsing and watcher recovery; separate cache directories prevent different worktree roots and desktop/web settings from repeatedly invalidating a cache inside shared node_modules. Tracking cache use makes the disk cost reclaimable without treating an old directory timestamp as proof that a running server is idle.

Linked Issue

Follow-up to #29345.

Visual Proof

N/A — build configuration only; no application UI or interaction changes.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Linux, Node 24.22.0, Bun 1.4.3; all tests used ORCA_BACKGROUND_LAUNCH=1.

  • pnpm tc
  • Focused config, watcher, packaging exclusion, and output-contract tests: 62 passed, 1 skipped.
  • Node-runtime config and watcher tests.
  • Cache cleanup, command orchestration, config resolution, and packaging tests under both Node and the normal Bun runner: 93 passed, 1 skipped each. Covers a real headless Vite server, multiple owners, exited owners, maintenance contention, symlinks, and the actual reclaim CLI against a temporary repository.
  • pnpm tc:node after the cleanup addition and final config integration.
  • After integrating the development source-map setting from main: 21 resolved-config and output-contract tests passed under Node.
  • Cleanup and real reclaim-command integration, including a same-hostname/different-WSL-distribution owner: 23 tests passed under Node.
  • After rebasing onto the latest watcher improvements: 19 Node-runtime watcher, config, and terminal-mirror tests passed; full typecheck passed.
  • Changed-code quality gate, Oxlint, formatting, and git diff --check.
  • Electron production bundle with renderer boot-graph verification, plus pnpm build:web.
  • In the performance-only comparison, hashes of every main, preload, and renderer production output matched the baseline exactly.

Local medians, with the original configurations and changed configurations run in alternating order, using the same source tree and default concurrency:

Step Elapsed before → after Peak RSS before → after
Production config loading 206 → 81 ms 237 → 190 MiB
Development main compilation 3.17 → 2.91 s 3170 → 2863 MiB
Full Electron bundle 7.45 → 7.49 s 5261 → 5286 MiB

Six fresh config loads per side with the final retention plugin; two dev-main and two full builds per side before the retention addition. Electron and web production builds were checked again with the final plugin. Full-build speed and memory did not improve reliably in this small sample. Cache collision avoidance was verified through configuration resolution; its performance benefit was not benchmarked across concurrent worktrees.

Review

Checked development/production config resolution, watch recovery and cleanup, and cache packaging exclusions. Cache paths use Node path resolution and work in folder workspaces too. Repository-wide cleanup follows the existing local Git-worktree scope and runs only on the execution host; folder workspaces without Git have no repository sweep. Unknown or pre-tracking caches are retained. No runtime or remote protocol changes.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Local validation was on Linux. macOS/Windows checks remain for CI.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

The complete test suite and packaged builds are covered by CI; the focused checks and normal JavaScript builds above passed locally. After the final rebase, full typecheck, root Oxlint, and anti-slop checks passed. Local pnpm lint reaches existing mobile import-cycle warnings with mobile dependencies installed; CI runs that audit before the mobile install, as documented in the workflow.

The full PR Checks workflow passed on commit 72316ac6fbfa3fda15df134421a5d77ca5f2ed6f, including the aggregate gate, all five unit shards, static analysis/typecheck, relay integration, and Linux/Windows packaging. Linux packaging passed after retrying a hidden-renderer test timeout.

@OrcaWin OrcaWin changed the title perf(build): skip unnecessary dev compilation and config work perf(build): skip dev minification and unused compiler loading Oct 16, 2026
@OrcaWin
OrcaWin marked this pull request as ready for review October 16, 2026 06:31
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Vite renderer and web builds now use worktree-local cache directories and a retention plugin. Worktree maintenance discovers Vite caches, checks their age and ownership, and reports or removes eligible caches. The cleanup runs through manual and automatic maintenance paths. Electron main build options are updated for development and production, and the process-host rebuild plugin loads TypeScript only in watch mode.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 72316

A restarted development server can leave an old cache protected from cleanup until it exits. The impact is bounded, but the retention lifecycle should be corrected.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 26 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly summarizes the main changes: reducing unnecessary build work and reclaiming Vite caches.
Description check Passed The description is complete and well aligned with the template. It explains the changes, rationale, testing, platform coverage, review considerations, and checklist status. The linked issue is referen…
Full details: Description check

Explanation

The description is complete and well aligned with the template. It explains the changes, rationale, testing, platform coverage, review considerations, and checklist status. The linked issue is referenced as #29345, and the lack of visual proof is correctly marked N/A.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@OrcaWin
OrcaWin force-pushed the OrcaWin/remove-build-overhead branch from 1570cba to 72d7f50 Compare October 16, 2026 06:34
@OrcaWin OrcaWin changed the title perf(build): skip dev minification and unused compiler loading perf(build): skip unnecessary work and reclaim Vite caches Oct 16, 2026
@OrcaWin
OrcaWin force-pushed the OrcaWin/remove-build-overhead branch 2 times, most recently from 1c436ba to 2930fb3 Compare October 16, 2026 07:20
@OrcaWin
OrcaWin force-pushed the OrcaWin/remove-build-overhead branch from 2930fb3 to cdf8448 Compare October 16, 2026 07:34
@OrcaWin
OrcaWin force-pushed the OrcaWin/remove-build-overhead branch from cdf8448 to 72316ac Compare October 16, 2026 07:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 676fa5f5-7aff-4fd8-8a39-00a383f74315
📥 Commits

Reviewing files that changed from the base of the PR and between 1c436bab70919466d66e9e252c8280787380d810 and 72316ac.

📒 Files selected for processing: 5
  • config/scripts/electron-vite-development-config.test.ts
  • config/scripts/electron-vite-output-contract.test.ts
  • config/scripts/reclaim-vite-caches.test.mjs
  • config/scripts/vite-cache-activity.mjs
  • electron.vite.config.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.


export async function retainViteCache(cacheRoot) {
const usage = join(cacheRoot, VITE_CACHE_USAGE_DIRECTORY)
const owner = join(usage, `${VITE_CACHE_HOST_ID}-${process.pid}-${randomUUID()}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Release owner markers when Vite restarts.

Each retention creates a new owner marker. On restart, Vite calls _closeServer('restart') and bypasses the server.close wrapper in config/build-plugins/vite-cache-retention.ts. The previous marker remains associated with a live PID, so cleanup cannot reclaim its cache if the restarted server uses another cache directory. Release ownership through Vite’s closeServer hook for both restart and shutdown. (raw.githubusercontent.com)

@OrcaWin
OrcaWin merged commit b3dfd54 into main Oct 16, 2026
57 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant