Skip to content

⚡ Bolt: Prevent main thread blocking during text streaming#44

Open
aloewright wants to merge 1 commit into
mainfrom
bolt-prevent-main-thread-block-streaming-3514953781856230736
Open

⚡ Bolt: Prevent main thread blocking during text streaming#44
aloewright wants to merge 1 commit into
mainfrom
bolt-prevent-main-thread-block-streaming-3514953781856230736

Conversation

@aloewright

Copy link
Copy Markdown
Owner

What:
Implemented React's useDeferredValue in apps/quill/client/components/playground-view.tsx to wrap the visibleOutput state. Updated the downstream useMemo dependency array for the snapshot calculation to rely on the deferred value instead of the rapidly streaming raw output.

Why:
When the LLM output streams in character-by-character (at an interval of approximately ~24ms), running the expensive synchronous analyzeText and scoreDeterministic computations on the active stream value blocks the main UI thread. This leads to dropped frames and lag/stuttering in the frontend text rendering.

Impact:
By decoupling the rapidly updating UI state from the state passed into the expensive synchronous useMemo operations, React can now prioritize smoothly rendering the active text stream while executing the heavy calculations safely in the background on slightly older state. This ensures that typing feels continuous.

Measurement:
Verify the improvement by loading up the local playground UI, initiating a stream, and observing the rendering performance through React DevTools Profiler or browser performance profiling tools—the main thread should no longer block during generation.


PR created automatically by Jules for task 3514953781856230736 started by @aloewright

Implements `useDeferredValue` for rapidly updating text streaming to prevent UI thread blocking while running synchronous text analysis.

Co-authored-by: aloewright <3641844+aloewright@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 26, 2026 05:27
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@aloewright, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 59 minutes and 31 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 332900b7-1fd8-4a49-975b-70a5eab206f0

📥 Commits

Reviewing files that changed from the base of the PR and between bab8f67 and b4f3ff6.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • apps/quill/client/components/playground-view.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-prevent-main-thread-block-streaming-3514953781856230736

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 and usage tips.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
postpilot b4f3ff6 May 26 2026, 05:27 AM

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces performance optimizations in the playground view component by utilizing React's useDeferredValue hook. This decouples the rapidly updating streaming text output from the expensive text analysis computations, preventing UI thread blocking and stuttering. A corresponding learning document has also been added to record this pattern. There are no review comments to address.

Copilot AI 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.

Pull request overview

Improves the Quill playground’s streaming UX by deferring the rapidly-updating output string before running expensive synchronous rubric analysis, reducing UI jank during character-by-character output streaming.

Changes:

  • Wrap visibleOutput with React useDeferredValue and base analyzeText memoization on the deferred value.
  • Add a Jules “bolt” note documenting the pattern for streaming text + expensive synchronous computations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/quill/client/components/playground-view.tsx Uses useDeferredValue to decouple streaming output updates from expensive rubric analysis recalculation.
.jules/bolt.md Adds a short note capturing the deferred-value approach for streaming text workloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +258 to +259
// Defer the rapidly updating text stream so that expensive analysis doesn't
// block the main thread.
Comment thread .jules/bolt.md

## 2024-05-24 - Deferring State for Streaming Text Calculations
**Learning:** When dealing with rapidly updating text streams (e.g., streaming LLM output character-by-character at intervals of ~24ms), running expensive synchronous computations (like text analysis/scoring) on the active stream value blocks the main UI thread and causes lag/stuttering.
**Action:** Always use React's `useDeferredValue` to decouple the rapidly updating UI state from the state passed into expensive `useMemo` or synchronous operations. This allows React to prioritize rendering the stream while running the heavy calculations in the background.
@aloewright aloewright enabled auto-merge (squash) June 4, 2026 05:07
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.

2 participants