Skip to content

⚡ Bolt: Avoid eager clone of entire Surface struct in WorkspaceModel - #391

Open
Lucenx9 wants to merge 1 commit into
mainfrom
bolt/optimize-surface-clone-18319778361575855755
Open

⚡ Bolt: Avoid eager clone of entire Surface struct in WorkspaceModel#391
Lucenx9 wants to merge 1 commit into
mainfrom
bolt/optimize-surface-clone-18319778361575855755

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

💡 What: Refactored WorkspaceModel methods (split_with, add_tab, prepare_root_surface_replacement, close_surface_with_replacement) to avoid eagerly cloning the entire Surface struct at the start of the function. Instead, the struct is borrowed, and only the required scalar fields (like workspace_id and cwd) are cloned before performing validation checks.

🎯 Why: The Surface struct is large because it contains a persisted_scrollback buffer (Option<String>) that can be up to 64KB. Calling clone() on it just to retrieve the workspace ID for a fast pre-validation check forces an unnecessary and expensive heap allocation. Early returns from these checks would still incur this cost.

📊 Impact: Reduces heap allocations and completely eliminates copying up to 64KB of buffer data on validation paths when closing or creating surfaces.

🔬 Measurement: Profile the allocations with memory analyzers during repeated split/close operations in workspaces heavily populated with large scrollback buffers.


PR created automatically by Jules for task 18319778361575855755 started by @Lucenx9

Summary

  • Refactored WorkspaceModel surface handling to borrow Surface values.
  • Cloned only required fields, such as workspace_id and cwd.
  • Reduced heap allocations and unnecessary persisted_scrollback buffer copies.
  • Preserved validation and observable behavior.

Impact

  • No user-visible behavior changes.
  • No native GTK or VTE changes.
  • No socket or core protocol changes.
  • No security or privacy impact.
  • No test changes reported.

Co-authored-by: Lucenx9 <185146821+Lucenx9@users.noreply.github.com>
@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 Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 277f6e6f-02dd-401b-9a0f-3573aadfd12e

📥 Commits

Reviewing files that changed from the base of the PR and between 5b45feb and d4efd1c.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • crates/forktty-core/src/model.rs

📝 Walkthrough

Walkthrough

The PR updates WorkspaceModel surface operations to borrow Surface values and clone only required workspace and working-directory fields. It also documents the optimization.

Changes

Surface lookup optimization

Layer / File(s) Summary
Surface creation operations
crates/forktty-core/src/model.rs, .jules/bolt.md
split_with and add_tab extract workspace and working-directory data without cloning complete Surface values. The learning note documents this approach.
Replacement and close operations
crates/forktty-core/src/model.rs
Root replacement and surface closing borrow model entries while extracting the required workspace context.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: rust

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main performance refactor in WorkspaceModel and identifies the affected area.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Privacy Boundary ✅ Passed The runtime diff only borrows Surface fields and constructs local model values; it adds no telemetry, network calls, or terminal-output persistence, and the only other change is a local learning note.
Terminal Command Safety ✅ Passed The patch changes only .jules/bolt.md and WorkspaceModel surface cloning in model.rs; it does not modify PTY, socket, worktree, shell, packaging, or notification command execution.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt/optimize-surface-clone-18319778361575855755

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4efd1cf9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .jules/bolt.md
@@ -0,0 +1,4 @@

## 2024-05-18 - Avoid Cloning Large Structs From The Model

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the one-off .jules directory

This file introduces .jules/ as a new top-level bucket solely for a tool-specific optimization note, rather than a durable repository content category or documentation colocated with the owning crate. Remove this artifact, or move genuinely durable guidance under the existing docs/ or crate structure, to keep the repository shape predictable.

AGENTS.md reference: AGENTS.md:L131-L131

Useful? React with 👍 / 👎.

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.

1 participant