Skip to content

⚡ Bolt: [performance improvement] Avoid eager string allocations in pane tree traversal#333

Open
Lucenx9 wants to merge 1 commit into
mainfrom
bolt/optimize-pane-tree-push-8410371843976446559
Open

⚡ Bolt: [performance improvement] Avoid eager string allocations in pane tree traversal#333
Lucenx9 wants to merge 1 commit into
mainfrom
bolt/optimize-pane-tree-push-8410371843976446559

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

💡 What: Refactored push_tab_to_leaf in pane_tree.rs to accept &str instead of an owned String (SurfaceId). Replaced .clone() in recursive tree traversal with a pass-by-reference, and deferred .to_owned() strictly to the point of insertion.

🎯 Why: In recursive structures like PaneNode::Split, passing owned Strings requires an O(N) sequence of .clone() operations for every child checked during traversal. This eagerly and unnecessarily allocates heap memory. By using &str, we pass memory references down the stack instead, reducing GC pressure and increasing traversal speed.

📊 Impact: Eliminates O(N) unnecessary string heap allocations when pushing new tabs into deep pane trees. The string is now allocated exactly once, achieving O(1) memory allocations for this action.

🔬 Measurement: Verified using cargo test -p forktty-core that logic correctness is maintained while tests pass perfectly. No regressions observed.


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

Summary

  • Optimizes pane-tree tab insertion by passing tab IDs by reference and allocating only at the target leaf.
  • No user-visible behavior, GTK/VTE, socket, or security/privacy changes.
  • Tests: cargo test -p forktty-core passes.

Updates `push_tab_to_leaf` signature in `forktty-core` to take a `&str` instead of an owned `String` (`SurfaceId`), eliminating unnecessary `O(N)` string clones during recursive pane tree traversal and deferring allocation (`.to_owned()`) until the exact target leaf match is confirmed.

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 10, 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: 7b4f04b1-6bad-46f7-9869-4ee4d95d7fb7

📥 Commits

Reviewing files that changed from the base of the PR and between aa546a7 and 0613f12.

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

📝 Walkthrough

Walkthrough

push_tab_to_leaf now accepts borrowed tab IDs, forwards them through recursive pane traversal, and converts them to owned strings only when storing them in a leaf. WorkspaceModel::add_tab passes the new ID by reference.

Changes

Tab ID ownership

Layer / File(s) Summary
Borrow tab ID through pane insertion
crates/forktty-core/src/model/pane_tree.rs, crates/forktty-core/src/model.rs
push_tab_to_leaf and its recursive calls use &str, while leaf insertion owns the value; add_tab passes &new_id without changing failure handling.

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

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 main change: reducing eager string allocations during pane tree traversal.
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 Patch only changes in-memory tab ID passing in pane-tree traversal; no telemetry, network calls, or new persistence paths were added.
Terminal Command Safety ✅ Passed Only pane-tree tab ID plumbing changed; no PTY/socket/shell/worktree/notification command-execution code was touched, so this safety check is not applicable.
✨ 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-pane-tree-push-8410371843976446559

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