Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-08-01 - Avoid Eager Allocations in Pane Tree Traversals

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 root metadata directory

This recreates a .jules/ top-level bucket for a single automation note, even though nothing in the repository consumes it; a repo-wide search only finds the prior CHANGELOG entry documenting removal of a stale .jules/bolt.md. Drop this artifact or place any durable performance documentation near the owning model module instead of adding another root content category.

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

Useful? React with πŸ‘Β / πŸ‘Ž.

**Learning:** In Rust, avoid calling `.clone()` on strings inside recursive tree traversal iterators like `.any()`. This eager allocation causes `O(N)` heap allocations when pushing down the call stack, even though the insertion only requires the string to be owned exactly once at the final insertion point.
**Action:** Pass `&str` instead of `String` during recursive lookups and defer the `.to_owned()` call strictly to the final successful match condition.
2 changes: 1 addition & 1 deletion crates/forktty-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ impl WorkspaceModel {
.workspaces
.get_mut(&workspace_id)
.expect("workspace verified above");
if !push_tab_to_leaf(&mut workspace.pane_tree, near_surface_id, new_id.clone()) {
if !push_tab_to_leaf(&mut workspace.pane_tree, near_surface_id, &new_id) {
return None;
}
workspace.focused_surface_id = new_id.clone();
Expand Down
6 changes: 3 additions & 3 deletions crates/forktty-core/src/model/pane_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,12 @@ pub(super) fn set_leaf_active_for_surface(node: &mut PaneNode, surface_id: &str)
pub(super) fn push_tab_to_leaf(
node: &mut PaneNode,
near_surface_id: &str,
new_tab_id: SurfaceId,
new_tab_id: &str,
) -> bool {
match node {
PaneNode::Leaf { tabs, active } => {
if tabs.iter().any(|id| id == near_surface_id) {
tabs.push(new_tab_id);
tabs.push(new_tab_id.to_owned());
*active = tabs.len() - 1;
true
} else {
Expand All @@ -660,6 +660,6 @@ pub(super) fn push_tab_to_leaf(
}
PaneNode::Split { children, .. } => children
.iter_mut()
.any(|child| push_tab_to_leaf(child, near_surface_id, new_tab_id.clone())),
.any(|child| push_tab_to_leaf(child, near_surface_id, new_tab_id)),
}
}
Loading