Skip to content

perf(common): implement copy-on-write behavior in formatters - #1905

Draft
liangfung wants to merge 1 commit into
mainfrom
feat/copy-on-write-formatters
Draft

perf(common): implement copy-on-write behavior in formatters#1905
liangfung wants to merge 1 commit into
mainfrom
feat/copy-on-write-formatters

Conversation

@liangfung

@liangfung liangfung commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Implements Copy-on-Write: Introduces helper functions mapOrOriginal, filterOrOriginal, and mapMessagePartsOrOriginal to replace in-place array/object mutations inside formatters.ui.
  • Immutable State Updates: Refactors compactTask, writeRenderWidgetOutput, and appendCheckpoint to perform immutable updates on messages and parts arrays instead of using in-place methods like unshift or push.
  • Preserves Reference Equality: Ensures that unmodified parts and messages conserve reference equality across formatters, avoiding unnecessary re-renders in the React-based UI of vscode-webui.

Perf

Before

image

After

image

Test plan

  • Run unit tests to verify copy-on-write behaviors and that UI snapshots are not mutated:
    • bun turbo test --filter=@getpochi/common
    • bun turbo test --filter=@getpochi/livekit
    • bun turbo test --filter=@getpochi/vscode-webui
  • Verify that types check successfully:
    • bun tsc
  • Format and lint checks:
    • bun check

🤖 Generated with Pochi | Task

…nt mutation

Introduce copy-on-write helper functions (mapOrOriginal, filterOrOriginal, mapMessagePartsOrOriginal) to avoid mutating message arrays and part objects in-place during formatters.ui processing.
Isolate latest user messages and update checkpoint/renderWidget operations immutably to preserve reference equality for unmodified chat history parts, avoiding unnecessary re-renders.

🤖 Generated with [Pochi](https://getpochi.com) | [Task](https://app.getpochi.com/share/p-31f6de164c5d468584ff9b1236c9d519)

Co-Authored-By: Pochi <noreply@getpochi.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.45946% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 38.39%. Comparing base (df49e9e) to head (b36f5df).

Files with missing lines Patch % Lines
...ebui/src/features/chat/lib/on-override-messages.ts 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1905      +/-   ##
==========================================
+ Coverage   38.31%   38.39%   +0.07%     
==========================================
  Files         772      772              
  Lines       82354    82447      +93     
  Branches     3951     4046      +95     
==========================================
+ Hits        31556    31656     +100     
+ Misses      50681    50674       -7     
  Partials      117      117              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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