Skip to content

perf(renderer): unmount closed workspace cleanup content - #13567

Open
nwparker wants to merge 1 commit into
mainfrom
nwparker/perf-unmount-workspace-cleanup-content
Open

perf(renderer): unmount closed workspace cleanup content#13567
nwparker wants to merge 1 commit into
mainfrom
nwparker/perf-unmount-workspace-cleanup-content

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

ELI5

After the Workspace Cleanup dialog was opened once, closing it hid the pixels but left the whole spreadsheet recalculating behind the curtain. Remote scans stream cumulative candidate lists, so the hidden dialog kept rebuilding review metadata, filtering rows, and running three sorts as those lists grew.

This keeps a tiny session shell alive for the work that really must continue in the background, while unmounting the expensive subscribed content 300 ms after close.

flowchart LR
  Open[Open: session + content] -->|close| Linger[Closed: content lingers 300 ms]
  Linger -->|reopen before timeout| Open
  Linger -->|timeout| Shell[Closed: session shell only]
  Shell -->|scan or removal callbacks| Shell
  Shell -->|reopen| Open
Loading

The session shell owns scan completion toasts, deletion progress, confirm-time candidate snapshots, queued-delete cleanup, late-settlement fencing, and the small UI state needed on reopen. The gated content owns the broad store subscriptions and all candidate review/filter/sort projections.

Quantitative proof

Closed after first use Before After
Retained useAppStore subscriptions 17 1
Delete-state projection on arbitrary store writes scans all D delete entries none
Candidate work after the 300 ms boundary review projection + filters + 3 sorts zero

The deterministic regression fixture closes the dialog, crosses the exact 300 ms boundary, then publishes 300 representative store writes: 100 streamed scans, 100 review-cache updates, and 100 delete-state updates. It observes 0 additional content renders, 0 projections, and only the one session-shell listener above baseline.

It also proves:

  • content remains mounted through 299 ms so the close animation cannot flash empty;
  • reopening at 299 ms cancels the pending unmount;
  • a deferred scan still emits its ready toast while content is gone, and Review reopens the dialog;
  • a deferred deletion keeps its 0/1 progress while closed, restores it on reopen, skips a duplicate scan, and settles normally.

For a streamed scan reaching N candidates, the old retained parent could repeat cumulative review/filter/index work across frames and three O(k log k) sorts per nonempty frame. Unmounting the parent removes that hidden cumulative work entirely.

Compatibility

  • Renderer lifecycle refactor only; no RPC, stream opcode, payload, persistence, or remote-wire change.
  • Direct SSH, local, git-worktree, and folder-workspace behavior is unchanged.
  • Scans and removals remain store-owned and continue while the visual content is unmounted.
  • No platform-specific path, shortcut, or Git behavior changed.
  • No visual or styling changes; the existing 300 ms close-animation safety window is preserved.

Regression results

  • Workspace Cleanup focused suite: 78/78 passed.
  • New lifecycle tests: 5/5 passed.
  • Full typecheck: passed.
  • Full lint, native/type-aware audits, reliability gates, max-lines ratchet, skill manifest, and localization gates: passed.
  • Full Vitest run: 49,211 passed, 103 skipped. Two unrelated failures remained:
    • the existing cross-version v799 staging checkout ENOENT;
    • the terminal hover-link timing fixture measured 109.06 ms against its 100 ms suite-load threshold, then passed immediately in isolation (1/1).

This is the Workspace Cleanup counterpart to #13525.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change extracts workspace cleanup scan and removal behavior into session hooks. The dialog now delegates modal state, selection, filtering, scanning, dismissal, and removal actions to useWorkspaceCleanupDialogSession. Dialog content remains mounted for 300 ms after closing and supports reopening during that period. Deferred scans can display readiness toasts after unmount. New tests cover mount gating, deferred scan notifications, and removal progress across close and reopen.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main performance change: unmounting closed Workspace Cleanup content.
Description check ✅ Passed The description clearly covers the change, testing, compatibility, and visual impact, but it omits dedicated AI Review Report and Security Audit sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@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: Pro Plus

Run ID: f01fac22-3997-4834-b04d-30f0c05f199c

📥 Commits

Reviewing files that changed from the base of the PR and between 6cdd019 and 621df99.

📒 Files selected for processing (6)
  • src/renderer/src/components/workspace-cleanup/WorkspaceCleanupDialog.mount-gating.test.tsx
  • src/renderer/src/components/workspace-cleanup/WorkspaceCleanupDialog.tsx
  • src/renderer/src/components/workspace-cleanup/workspace-cleanup-dialog-session.test.tsx
  • src/renderer/src/components/workspace-cleanup/workspace-cleanup-dialog-session.ts
  • src/renderer/src/components/workspace-cleanup/workspace-cleanup-removal-session.ts
  • src/renderer/src/components/workspace-cleanup/workspace-cleanup-scan-session.ts

Comment on lines +78 to +88
function formatWorkspaceCleanupReadyToastDescription(
inactiveCount: number,
suggestedCount: number
): string {
if (inactiveCount === 0) {
return 'No inactive workspaces found.'
}
const inactiveNoun = inactiveCount === 1 ? 'workspace' : 'workspaces'
const suggestedNoun = suggestedCount === 1 ? 'suggestion' : 'suggestions'
return `${inactiveCount} inactive ${inactiveNoun} found, with ${suggestedCount} cleanup ${suggestedNoun}.`
}

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Localize the ready-toast description.

The toast title and action label use translate(), but this description returns raw English text. The plural choice also uses a two-form ternary, which is wrong for languages with more than two plural forms. Route the description through translate() with interpolated counts and locale keys generated by localize-renderer-strings.mjs (first 10 characters of the SHA-1 of <filePath>:<text>).

Note: src/renderer/src/components/workspace-cleanup/workspace-cleanup-dialog-session.test.tsx Line 98 asserts the literal description text, so update that assertion with the change.

Based on learnings: renderer locale keys are the first 10 characters of the SHA-1 hash of <filePath>:<text>, matching localize-renderer-strings.mjs.

Source: Learnings

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