-
Notifications
You must be signed in to change notification settings - Fork 29
🤖 perf: improve Review panel performance and fix UI flashes #946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
a38e1df to
53eb3e5
Compare
ed09674 to
f27c96a
Compare
f27c96a to
56e5a8f
Compare
- Migrate MarkdownComponents.tsx to use highlightCode() from worker client - Delete shikiHighlighter.ts, inline fallback into highlightWorkerClient.ts - Move MAX_DIFF_SIZE_BYTES to highlightDiffChunk.ts (only consumer) - All highlighting now shares LRU cache and worker (or fallback)
Combine two CRC32 hashes with different seeds to create a 64-bit key, reducing collision probability for the LRU cache.
Web Crypto API is built-in and hardware-accelerated, no external deps needed.
Replaces manual message ID tracking, pending request maps, and postMessage/onmessage boilerplate with Comlink's proxy-based RPC. - Worker exposes API via Comlink.expose() - Client wraps worker via Comlink.wrap() - Exceptions propagate naturally - ~30 lines removed
Reset hasLoadedOnce and hunks when workspace changes to prevent showing stale 'No changes found' message from previous workspace.
Replace independent state variables (isLoadingHunks, hasLoadedOnce,
error, hunks, truncationWarning) with a single DiffState union:
type DiffState =
| { status: 'loading' }
| { status: 'loaded'; hunks: DiffHunk[]; truncationWarning: string | null }
| { status: 'error'; message: string }
This makes invalid states unrepresentable - it's now impossible to
show 'No changes found' while loading because the type system
enforces that hunks only exist in the 'loaded' state.
Add workspaceId to DiffState to distinguish between: - Refreshing same workspace: show stale data while loading (no flash) - Switching workspaces: show loading indicator (no stale data) The state machine now correctly handles: 1. Initial load → 'loading' → 'loaded' 2. Refresh (same workspace) → 'refreshing' (keeps hunks visible) → 'loaded' 3. Workspace switch → 'loading' (clears stale hunks) → 'loaded'
…itch
Instead of tracking workspaceId in state and checking it everywhere,
use React's key prop to force remount when workspace changes.
This is simpler and more reliable:
- Component unmounts, clearing all state
- New instance mounts with fresh { status: 'loading' }
- No stale data from previous workspace can leak through
Simplifies DiffState by removing workspaceId from the union.
68356e6 to
0e3dbf3
Compare
Also adds worker name for DevTools visibility. TODO: For 20k+ line diffs, the main thread bottleneck is likely DOM rendering (thousands of HunkViewer components), not highlighting. Consider adding virtualization (@tanstack/react-virtual) to only render visible hunks.
- Change main-thread fallback to use dynamic import() so shiki isn't bundled with the main thread code path - Add ESLint rule to enforce shiki is only imported in highlightWorker.ts - Type-only imports are allowed (erased at compile time) This ensures the 9.7MB @shikijs/langs package is only loaded in the web worker, not blocking the main thread during app startup.
ammario
approved these changes
Dec 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Performance improvements and UI polish for the Review panel when viewing large diffs.
Manually verified: Much better performance when viewing large diffs (~3000+ lines).
Performance
UI Flash Fixes
Refactoring
shikiHighlighter.ts, consolidated intohighlightWorkerClient.tsbuildGitDiffCommandtosrc/common/utils/git/diffParser.tsRIGHT_SIDEBAR_TAB_KEY, etc.)State Machine
loading→loadedloaded→refreshing→loadedloaded{ws1}→loading→loaded{ws2}Testing
make typecheck✓make static-check✓bun test src/browser/utils/highlighting/highlightDiffChunk.test.ts— 18 passGenerated with
mux