Skip to content

⚡ Bolt: Optimize push_tab_to_leaf heap allocations - #373

Open
Lucenx9 wants to merge 1 commit into
mainfrom
bolt-optimize-push-tab-to-leaf-6611019296646207069
Open

⚡ Bolt: Optimize push_tab_to_leaf heap allocations#373
Lucenx9 wants to merge 1 commit into
mainfrom
bolt-optimize-push-tab-to-leaf-6611019296646207069

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Jul 25, 2026

Copy link
Copy Markdown
Owner

💡 What:
Optimized push_tab_to_leaf in crates/forktty-core/src/model/pane_tree.rs to take new_tab_id as a string slice reference (&str) rather than an owned string (String / SurfaceId). The caller in model.rs was updated to pass a reference instead of unconditionally cloning new_id.

🎯 Why:
During pane tree operations that insert new tabs, push_tab_to_leaf recursively traverses PaneNode::Split nodes using an .any() iterator closure. Previously, the new_tab_id string was cloned on every single recursive call during this traversal, leading to O(N) unnecessary heap allocations where N is the number of child splits traversed.

📊 Impact:
Significantly reduces redundant String allocations during tab creation or moving operations within complex workspaces, especially when navigating deep split hierarchies. The string allocation is completely deferred until the precise target leaf is discovered and the push operation is imminent.

🔬 Measurement:
Tested and verified via cargo check -p forktty-core and cargo test -p forktty-core. The optimization strictly preserves existing behavior while improving execution speed and memory efficiency.


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

  • Optimizes tab insertion by passing the new tab ID by reference during pane-tree traversal and allocating an owned string only at the destination leaf.
  • No user-visible behavior, GTK/VTE behavior, or socket changes.
  • Core Rust implementation updated; validated with cargo check -p forktty-core and cargo test -p forktty-core.
  • No security or privacy impact.

…as reference

Passes `new_tab_id` as `&str` instead of `String` to prevent redundant heap
allocations during the `.any()` tree traversal inside `push_tab_to_leaf`. The
string is now only allocated exactly once (via `.to_string()`) when the target
insertion point is actually found.

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 25, 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: f9ff0e18-4ec9-4675-b8d8-2882525ce442

📥 Commits

Reviewing files that changed from the base of the PR and between e6b0e87 and 57c46a2.

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

📝 Walkthrough

Walkthrough

The tab insertion path now passes the new surface ID by reference through pane-tree traversal and converts it to an owned string only when inserting into a leaf.

Changes

Tab ID borrowing

Layer / File(s) Summary
Borrow tab ID through pane-tree insertion
crates/forktty-core/src/model.rs, crates/forktty-core/src/model/pane_tree.rs
WorkspaceModel::add_tab passes the new ID by reference; push_tab_to_leaf threads the borrowed ID recursively and owns it only at leaf insertion.

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

Possibly related PRs

  • Lucenx9/forktty#338: Updates push_tab_to_leaf and WorkspaceModel::add_tab to pass the new tab ID by reference.
  • Lucenx9/forktty#340: Uses borrowed tab IDs through pane-tree recursion and allocates only at insertion.
  • Lucenx9/forktty#341: Reduces cloning during tab creation in the same model path.

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 is concise and accurately describes the allocation optimization in push_tab_to_leaf.
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 Only a local allocation/parameter-passing change in pane-tree tab insertion; no telemetry, network, or new persistence paths were added.
Terminal Command Safety ✅ Passed PASS: Only pane-tree tab-id passing changed; no PTY/socket/shell/packaging/notification execution paths were modified.
✨ 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-push-tab-to-leaf-6611019296646207069

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.

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