Skip to content

⚡ Optimize mock workspace update by removing structuredClone - #393

Closed
seonghobae wants to merge 4 commits into
developfrom
performance-mock-clone-15743645489139680554
Closed

⚡ Optimize mock workspace update by removing structuredClone#393
seonghobae wants to merge 4 commits into
developfrom
performance-mock-clone-15743645489139680554

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What: Replaced structuredClone(mockWorkspace) with just mockWorkspace in triggerMockUpdate since the payload will be structuredCloned inside the parse function anyway, preventing redundant clones.
🎯 Why: To improve performance by eliminating an unnecessary structuredClone in the mock event emitter which is executed on every workspace update.
📊 Measured Improvement: Baseline was 7301.19ms for 10000 events. Optimized is 3472.35ms. That is a ~2.10x speedup.


PR created automatically by Jules for task 15743645489139680554 started by @seonghobae

@google-labs-jules

Copy link
Copy Markdown

👋 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.

@opencode-agent

opencode-agent Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

  • Head SHA: 596bfae833a9f14abd4064637b99fc59b1e6b7a6
  • Workflow run: 28165718713
  • Workflow attempt: 1
  • Gate result: REQUEST_CHANGES (approval step)

OpenCode reviewed the current-head evidence but found unresolved human review threads before approval.

  • Problem: OpenCode reached an APPROVE control result, but the approval step found unresolved, non-outdated human review thread evidence on the current pull request.
  • Root cause: Human review feedback can arrive after bounded model evidence is prepared, so the approval step must re-query GitHub immediately before publishing an approval.
  • Fix: Address or resolve the listed human review thread(s), then re-run OpenCode on the current head.
  • Regression test: Keep the approval gate querying reviewThreads(first: 100) after model output and before create_pull_review APPROVE.

Review thread evidence

Latest unresolved human review thread evidence

apps/desktop/src/lib/job_runner.ts line 62

  • Latest human comment: @copilot-pull-request-reviewer at 2026-06-25T00:45:00Z

  • Comment URL: ⚡ Optimize mock workspace update by removing structuredClone #393 (comment)

  • Comment excerpt: This changes the event payload semantics from ‘fresh deep-cloned object per event’ to ‘shared reference to a long-lived object’. Any listener that mutates event.payload (or stores it and later mutates) can now (1) affect other listeners in the same emission and (2) permanently mutate mockWorkspace, impacting future updates. If the intent is to rely on parseRehearsalWorkspace() cloning, consider enforcing immutability at the emitter boundary (e.g., emit a frozen/deep-frozen object, or change the event payload type to a deep readonly so listeners can’t mutate), or keep cloning here but rem

  • Result: REQUEST_CHANGES

  • Reason: unresolved human review thread(s) were present before approval.

  • Head SHA: 596bfae833a9f14abd4064637b99fc59b1e6b7a6

  • Workflow run: 28165718713

  • Workflow attempt: 1

Copilot AI review requested due to automatic review settings June 25, 2026 00:28

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

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Optimizes mock workspace update emissions by removing a redundant deep clone, relying on downstream parsing to clone the payload.

Changes:

  • Removed structuredClone(mockWorkspace) in triggerMockUpdate to avoid cloning on every mock update.
  • Added a small benchmark script (bench.cjs) to compare baseline vs optimized behavior.

Reviewed changes

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

File Description
bench.cjs Adds a micro-benchmark to quantify the impact of removing the extra clone.
apps/desktop/src/lib/job_runner.ts Removes an extra structuredClone when emitting mock workspace update events.

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

Comment on lines +61 to 62
const payload = mockWorkspace;
mockListeners.forEach(listener => listener({ payload }));
Comment thread bench.cjs Outdated
Comment on lines +50 to +63
let start = performance.now();
for (let i = 0; i < N; i++) {
triggerMockUpdateBaseline();
}
let end = performance.now();
const baselineTime = end - start;
console.log(`Baseline: ${baselineTime.toFixed(2)} ms`);

start = performance.now();
for (let i = 0; i < N; i++) {
triggerMockUpdateOptimized();
}
end = performance.now();
const optimizedTime = end - start;

@opencode-agent opencode-agent 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.

OpenCode reviewed the current-head evidence but found unresolved human review threads before approval.

  • Problem: OpenCode reached an APPROVE control result, but the approval step found unresolved, non-outdated human review thread evidence on the current pull request.
  • Root cause: Human review feedback can arrive after bounded model evidence is prepared, so the approval step must re-query GitHub immediately before publishing an approval.
  • Fix: Address or resolve the listed human review thread(s), then re-run OpenCode on the current head.
  • Regression test: Keep the approval gate querying reviewThreads(first: 100) after model output and before create_pull_review APPROVE.

Review thread evidence

Latest unresolved human review thread evidence

apps/desktop/src/lib/job_runner.ts line 62

  • Latest human comment: @copilot-pull-request-reviewer at 2026-06-25T00:45:00Z
  • Comment URL: #393 (comment)
  • Comment excerpt: This changes the event payload semantics from ‘fresh deep-cloned object per event’ to ‘shared reference to a long-lived object’. Any listener that mutates event.payload (or stores it and later mutates) can now (1) affect other listeners in the same emission and (2) permanently mutate mockWorkspace, impacting future updates. If the intent is to rely on parseRehearsalWorkspace() cloning, consider enforcing immutability at the emitter boundary (e.g., emit a frozen/deep-frozen object, or change the event payload type to a deep readonly so listeners can’t mutate), or keep cloning here but rem

bench.cjs line 63

  • Latest human comment: @copilot-pull-request-reviewer at 2026-06-25T00:45:00Z

  • Comment URL: #393 (comment)

  • Comment excerpt: The benchmark always runs baseline first, then optimized, which can bias results due to JIT warmup, cache effects, or GC timing differences between the two runs. To make the committed benchmark more reliable/reproducible, run multiple rounds and alternate the order (or randomize it) and report an average/median across rounds.

  • Result: REQUEST_CHANGES

  • Reason: unresolved human review thread(s) were present before approval.

  • Head SHA: c98a2620ca869194c9da40f0364f9e2ab8b0d15c

  • Workflow run: 28138618121

  • Workflow attempt: 1

@opencode-agent opencode-agent 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.

OpenCode reviewed the current-head evidence but found unresolved human review threads before approval.

  • Problem: OpenCode reached an APPROVE control result, but the approval step found unresolved, non-outdated human review thread evidence on the current pull request.
  • Root cause: Human review feedback can arrive after bounded model evidence is prepared, so the approval step must re-query GitHub immediately before publishing an approval.
  • Fix: Address or resolve the listed human review thread(s), then re-run OpenCode on the current head.
  • Regression test: Keep the approval gate querying reviewThreads(first: 100) after model output and before create_pull_review APPROVE.

Review thread evidence

Latest unresolved human review thread evidence

apps/desktop/src/lib/job_runner.ts line 62

  • Latest human comment: @copilot-pull-request-reviewer at 2026-06-25T00:45:00Z

  • Comment URL: #393 (comment)

  • Comment excerpt: This changes the event payload semantics from ‘fresh deep-cloned object per event’ to ‘shared reference to a long-lived object’. Any listener that mutates event.payload (or stores it and later mutates) can now (1) affect other listeners in the same emission and (2) permanently mutate mockWorkspace, impacting future updates. If the intent is to rely on parseRehearsalWorkspace() cloning, consider enforcing immutability at the emitter boundary (e.g., emit a frozen/deep-frozen object, or change the event payload type to a deep readonly so listeners can’t mutate), or keep cloning here but rem

  • Result: REQUEST_CHANGES

  • Reason: unresolved human review thread(s) were present before approval.

  • Head SHA: 596bfae833a9f14abd4064637b99fc59b1e6b7a6

  • Workflow run: 28165718713

  • Workflow attempt: 1

@seonghobae

Copy link
Copy Markdown
Collaborator Author

Closing rather than carrying this forward. The core change removes the mock event payload clone and exposes the long-lived mockWorkspace object by reference to listeners, which changes the emitter-boundary semantics called out in review. This branch also contains unrelated workflow/test churn and conflicts, so it is not an approval-ready performance fix.

@seonghobae seonghobae closed this Jun 28, 2026
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