Skip to content

⚡ Bolt: Avoid cloning large scrollback buffers during terminal init - #389

Open
Lucenx9 wants to merge 1 commit into
mainfrom
bolt/optimize-terminal-spawn-scrollback-18370122869034714600
Open

⚡ Bolt: Avoid cloning large scrollback buffers during terminal init#389
Lucenx9 wants to merge 1 commit into
mainfrom
bolt/optimize-terminal-spawn-scrollback-18370122869034714600

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Aug 4, 2026

Copy link
Copy Markdown
Owner

💡 What: Eliminated .clone() on surface.persisted_scrollback (which can be up to 64KB) during terminal spawn by computing the scrollback bytes directly inside the model's Mutex lock scope.
🎯 Why: Cloning large string allocations out of a lock just to immediately pass them to read-only parser functions causes unnecessary and expensive heap allocations in a hot path.
📊 Impact: Reduces memory allocations and CPU overhead during new terminal pane instantiation by processing the persistent scrollback purely by reference.
🔬 Measurement: Profile controller/embedded_spawn execution on terminal creation to observe zero heap allocations for the scrollback payload before passing to the backend.


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

  • Preserves terminal scrollback behavior while reducing allocations during terminal pane creation.
  • Borrows persisted scrollback within the model mutex instead of cloning it.
  • Limits changes to the GTK embedded-spawn path. No VTE, socket, or core Rust API changes.
  • No security or privacy impact identified.
  • Profile controller/embedded_spawn to measure CPU and heap allocation improvements.

Eliminated `.clone()` on `surface.persisted_scrollback` (which can be up to 64KB) during terminal spawn by computing the scrollback bytes directly inside the model's `Mutex` lock scope.

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 4, 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: 7a8b9215-151e-47f2-995d-9b84fee631af

📥 Commits

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

📒 Files selected for processing (2)
  • .jules/bolt.md
  • crates/forktty-ui-gtk/src/gtk_app/controller/embedded_spawn.rs

📝 Walkthrough

Walkthrough

The change removes unnecessary cloning of persisted scrollback during restoration and initial snapshot checks. It also documents lock-scoped borrowing with .as_deref().

Changes

Scrollback borrowing

Layer / File(s) Summary
Lock-scoped scrollback processing
crates/forktty-ui-gtk/src/gtk_app/controller/embedded_spawn.rs, .jules/bolt.md
Scrollback restoration and initial snapshot detection borrow persisted data while the model lock is held. Documentation records the .as_deref() pattern and lock-scoped processing guidance.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • Lucenx9/forktty#369: Modifies the same scrollback restoration and snapshot logic to avoid cloning persisted scrollback.

Suggested labels: frontend, rust, gtk

🚥 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 avoiding scrollback buffer cloning during terminal initialization.
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 diff only replaces scrollback cloning with borrowed references inside existing lock scopes; it adds no telemetry, network, or new persistence path. Bounded local session storage remains documen...
Terminal Command Safety ✅ Passed The commit only borrows persisted scrollback inside existing lock scopes; it does not change 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-terminal-spawn-scrollback-18370122869034714600

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: 2bbd94f67f

ℹ️ 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,3 @@
## 2024-08-04 - [Avoid Eager Cloning from Mutex]

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 root bucket

This commit creates a new top-level directory solely for a task-specific automation note, rather than a durable category of project content. Keeping this artifact makes the repository structure less predictable and leaves an unowned document that can become stale; omit it instead of introducing .jules/.

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