Skip to content

⚡ Bolt: [performance improvement] - #384

Open
Lucenx9 wants to merge 1 commit into
mainfrom
bolt-tree-traversal-clone-3686581746851882001
Open

⚡ Bolt: [performance improvement]#384
Lucenx9 wants to merge 1 commit into
mainfrom
bolt-tree-traversal-clone-3686581746851882001

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Jul 29, 2026

Copy link
Copy Markdown
Owner

💡 What: Refactored recursive PaneNode traversal functions (replace_leaf_with_split and push_tab_to_leaf) to pass the target object by value instead of a reference. It returns the unconsumed object in a Result::Err if it fails, which avoids redundant cloning during iterations over children.

🎯 Why: To improve performance by reducing heap allocations. The previous code .clone()d the entire node on each sibling during .any() iteration within the tree traversal, creating O(N) eager string and vector allocations in forktty-core.

📊 Impact: Reduces PaneNode (which contains vectors and potentially long strings) and SurfaceId heap allocations from O(N) (per sibling visited in a split) down to exactly O(1) (only one allocation is reused across the entire search path).

🔬 Measurement: Verify tests run successfully using cargo test -p forktty-core and see cat crates/forktty-core/src/model/pane_tree.rs.


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

Summary

  • Refactored pane-tree traversal to transfer ownership without eager cloning, reducing allocations along recursive searches.
  • Preserved split and tab insertion behavior while returning unconsumed objects on traversal failure.

Impact

  • User-visible: No behavior change expected.
  • GTK/VTE: No impact.
  • Socket/core Rust: Core pane-tree ownership and result handling updated; socket behavior unchanged.
  • Tests: Verify with cargo test -p forktty-core.
  • Security/privacy: No changes.

Refactor `replace_leaf_with_split` and `push_tab_to_leaf` in `crates/forktty-core/src/model/pane_tree.rs` to take ownership of the inserted node and return it in `Err` on recursive traversal failure. This completely eliminates the need to eagerly `.clone()` the node at every single visited sibling in the tree, turning an `O(N)` heap allocation hot-path into `O(1)` allocations.

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 Jul 29, 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: 10c6e694-4efc-4a3d-aefb-6acf0089425e

📥 Commits

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

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

📝 Walkthrough

Walkthrough

Tree traversal insertion methods now use Result to return uninserted ownership on failure. Workspace model callers adapt to the new return types while preserving existing success and failure behavior. Documentation records the ownership-passing approach.

Changes

Pane tree insertion flow

Layer / File(s) Summary
Recursive insertion contracts
crates/forktty-core/src/model/pane_tree.rs, .jules/bolt.md
replace_leaf_with_split and push_tab_to_leaf propagate uninserted values through recursive failures and return Ok(()) after insertion.
Workspace model integration
crates/forktty-core/src/model.rs
split_with and add_tab use Result status checks while preserving existing failure handling.

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

Possibly related PRs

  • Lucenx9/forktty#383: Modifies the same push_tab_to_leaf signature and its WorkspaceModel::add_tab call site.
  • Lucenx9/forktty#375: Covers the same Result<(), SurfaceId> conversion and caller handling.
  • Lucenx9/forktty#373: Changes how the new tab identifier is threaded through the same tree traversal.

Suggested labels: rust

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is too generic and does not clearly describe the pane tree traversal refactor or affected area. Use a concise descriptive title like "forktty-core: avoid cloning in pane tree traversal".
✅ 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 Changes are limited to in-memory pane traversal and model call sites; no telemetry, remote calls, or new persistence of terminal output were added.
Terminal Command Safety ✅ Passed No PTY/socket/worktree/shell/packaging/notification execution paths were changed; diff only refactors pane-tree ownership traversal.
✨ 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-tree-traversal-clone-3686581746851882001

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: c9f169e39c

ℹ️ 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-18 - [Avoid clone in tree traversal]

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 reintroduced .jules root artifact

This creates .jules/ as a new root bucket for a three-line automation learning note; rg --hidden finds no consumer, and CHANGELOG.md:2302 records that this same tool-note path had already been removed as stale. It therefore adds persistent repository structure for non-durable, single-tool metadata; remove it rather than committing it at the repository root.

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