Skip to content

⚡ Bolt: [performance improvement] - #390

Open
Lucenx9 wants to merge 4 commits into
mainfrom
bolt-perf-pane-tree-clone-2988142760334078877
Open

⚡ Bolt: [performance improvement]#390
Lucenx9 wants to merge 4 commits into
mainfrom
bolt-perf-pane-tree-clone-2988142760334078877

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Aug 6, 2026

Copy link
Copy Markdown
Owner

💡 What: Refactored replace_leaf_with_split and push_tab_to_leaf in pane_tree.rs to return Result<(), T> instead of bool, passing new_leaf and new_tab_id by ownership and returning them on failure.
🎯 Why: Previously, the .any() closures inside these recursive tree traversal functions eagerly called .clone() on complex values (like PaneNode or SurfaceId/String) for every iteration over child nodes. This caused redundant heap allocations even when a match wasn't found.
📊 Impact: Eliminates O(N) redundant heap allocations during pane splitting and tab pushing operations (where N is the number of child splits visited), reducing memory overhead.
🔬 Measurement: Run the test suite and benchmark terminal split/tab operations to verify correctness and potential latency improvements.


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

Summary

  • Refactored pane-tree operations to return owned values through Result<(), T> when no target is found.
  • Removed redundant PaneNode and SurfaceId clones during recursive searches.
  • No user-visible, GTK, VTE, socket, or security behavior changes.
  • No test changes or test results were reported.

Refactored `replace_leaf_with_split` and `push_tab_to_leaf` in `pane_tree.rs` to return `Result<(), T>` instead of `bool`, passing `new_leaf` and `new_tab_id` by ownership and returning them on failure. This avoids eager `.clone()` in `.any()` closures during recursive tree traversals.

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 6, 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: 8864733a-0685-43cf-a079-8eedbe8bf3ea

📥 Commits

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

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

📝 Walkthrough

Walkthrough

Pane-tree mutation helpers now return unconsumed values through Result on failed searches. Recursive traversal avoids cloning PaneNode and SurfaceId values. Callers and Rust performance guidance were updated.

Changes

Pane-tree ownership refactor

Layer / File(s) Summary
Mutation result flow
crates/forktty-core/src/model/pane_tree.rs, crates/forktty-core/src/model.rs
replace_leaf_with_split and push_tab_to_leaf now return Result, propagate owned values through recursive traversal, and update callers to check success or failure.
Ownership optimization guidance
.jules/bolt.md
The Rust guideline now recommends returning owned values through Result instead of cloning them in recursive iterator closures.

Estimated code review effort: 3 (Moderate) | ~15 minutes

Possibly related PRs

  • Lucenx9/forktty#384: Directly related ownership-based Result traversal changes for both pane-tree operations.
  • Lucenx9/forktty#375: Related push_tab_to_leaf ownership and Result changes.
  • Lucenx9/forktty#388: Related extension of push_tab_to_leaf result propagation to replace_leaf_with_split.

Suggested labels: rust

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title indicates a performance change but does not identify the Rust pane-tree refactor or the eliminated cloning. Use a concise descriptive title such as “rust: avoid redundant cloning in pane-tree mutations”.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 commit changes only local pane-tree ownership and caller result handling plus a guideline file; it adds no telemetry, network calls, terminal-output persistence, or remote data transfer.
Terminal Command Safety ✅ Passed The patch changes only pane-tree ownership handling, its model call sites, and documentation; 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-perf-pane-tree-clone-2988142760334078877

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: 51fd515ff7

ℹ️ 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-05-15 - [Avoid redundant String clone in recursive tree search closures]

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 recreates a tool-specific top-level directory solely for a note about one forktty-core optimization, and the reviewed tree contains no consumer for .jules/bolt.md. Remove this generated metadata, or place any durable rationale beside the pane-tree implementation, rather than permanently expanding the repository root for a single feature.

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

Useful? React with 👍 / 👎.

google-labs-jules Bot and others added 3 commits August 6, 2026 17:22
Refactored `replace_leaf_with_split` and `push_tab_to_leaf` in `pane_tree.rs` to return `Result<(), T>` instead of `bool`, passing `new_leaf` and `new_tab_id` by ownership and returning them on failure. This avoids eager `.clone()` in `.any()` closures during recursive tree traversals.

Co-authored-by: Lucenx9 <185146821+Lucenx9@users.noreply.github.com>
Refactored `replace_leaf_with_split` and `push_tab_to_leaf` in `pane_tree.rs` to return `Result<(), T>` instead of `bool`, passing `new_leaf` and `new_tab_id` by ownership and returning them on failure. This avoids eager `.clone()` in `.any()` closures during recursive tree traversals.

Co-authored-by: Lucenx9 <185146821+Lucenx9@users.noreply.github.com>
Refactored `replace_leaf_with_split` and `push_tab_to_leaf` in `pane_tree.rs` to return `Result<(), T>` instead of `bool`, passing `new_leaf` and `new_tab_id` by ownership and returning them on failure. This avoids eager `.clone()` in `.any()` closures during recursive tree traversals.

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