Skip to content

fix(ui): prepare diffs off the render thread - #34415

Closed
jerrydong1988 wants to merge 7 commits into
anomalyco:devfrom
jerrydong1988:pr/fix-diff-worker
Closed

fix(ui): prepare diffs off the render thread#34415
jerrydong1988 wants to merge 7 commits into
anomalyco:devfrom
jerrydong1988:pr/fix-diff-worker

Conversation

@jerrydong1988

@jerrydong1988 jerrydong1988 commented Jun 29, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #34437

Type of change

  • Bug fix
  • Refactor / code improvement

What does this PR do?

Moves expensive diff preparation off the UI render thread into a Web Worker to prevent UI freezes on large diffs (e.g., C++ projects like llama.cpp on Windows).

Root cause: execEditLength ran synchronously in the render thread during diff computation, blocking frame rendering for hundreds of milliseconds.

Changes:

  • New diff infrastructure in packages/ui/src/diff/: worker, client, protocol, resource, client-core
  • Updated session components (review, turn, message-part, apply-patch) to use createPreparedDiff instead of synchronous diff parsing
  • Components now receive pending or prepared state and remain pure renderers

Performance (full-context replacement, 1,536 old + 1,536 new lines):

Metric Before After Change
Max frame gap 233ms 67ms 71% lower
p95 frame gap 33ms 17ms 50% lower

Original implementation by @Hona. Rebased onto latest dev with updated imports for session-ui migration and inlined worker helpers to avoid circular dependencies.

How did you verify your code works?

  • Original author ran 5 isolated Chromium runs showing 71% frame gap reduction
  • bun test passes for diff infrastructure unit tests
  • bun typecheck passes
  • Built and used on Windows with large C++ diff sessions — no freeze
  • GitHub Actions CI build + package succeeds
  • render-purity.test.ts updated to exclude worker.ts (the worker IS the diff parser)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Move expensive diff preparation off the UI render thread into a Web Worker
to prevent UI freezes on large diffs (e.g., Windows C++ projects).

Performance: max frame gap 233ms → 66ms (71% lower).

Original commit by @Hona (PR anomalyco#31309). Rebased onto latest dev with:
- Updated import paths for packages/session-ui migration
- Inlined session-diff helpers in worker to avoid circular deps
- Resolved mock-server.ts type conflicts
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Related PR Found

PR #31309: fix(ui): prepare diffs off the render thread
#31309

This is the original PR that the current PR (#34415) is rebasing. The PR description explicitly states: "Replaces PR #31309" and credits the original implementation to @Hona. PR #34415 is a rebase of #31309 onto the latest dev branch with updated import paths and resolved conflicts.

Other potentially related PRs addressing similar performance issues:

However, since PR #34415 explicitly replaces/rebases PR #31309, that's the key relationship. PRs #33198 and #30441 are separate fixes for related (but different) performance issues.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop renderer freezes on large file diffs (synchronous diff parsing on UI thread)

2 participants