perf(terminal): O(1) is_any_ai_block_focused via ancestor set#13113
perf(terminal): O(1) is_any_ai_block_focused via ancestor set#13113acarl005 wants to merge 1 commit into
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I completed the review and no human review was requested for this pull request. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR optimizes TerminalView::is_any_ai_block_focused by computing the focused view's ancestor chain once and checking AI block handles against that set instead of walking the focus ancestry for each rich content view.
Concerns
No blocking concerns found. The new implementation preserves the existing self-or-child semantics because view_ancestors includes the focused view itself, and no approved spec context was available for additional implementation/spec validation.
Verdict
Found: 0 critical, 0 important, 0 suggestions
Approve
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
bc7cbbe to
f9f0193
Compare
35dacbd to
3fd5226
Compare
f9f0193 to
e5d6e80
Compare
07b7b3b to
cc6d905
Compare
e5d6e80 to
bcecab0
Compare
bcecab0 to
e0445ff
Compare
cc6d905 to
75061d8
Compare

Description
Part of a stack of performance fixes for #9799.
This PR:
is_any_ai_block_focusedinterminal/view.rswas called on every render of a terminal view that contains AI blocks. It iterated all N AI block IDs and calledis_self_or_child_focusedon each, which internally calledview_ancestors()— an O(depth) walk of the view tree — each time. With 3000+ AI blocks, this was O(N × depth) per render.Now computes
view_ancestorsonce into aHashSet<EntityId>, then checks each AI block ID against the set in O(1), making the function O(N) total (and dominated by the O(depth) setup, which is constant relative to N).Linked Issue
Fixes #9799
ready-to-specorready-to-implement.Testing
Manually loaded a conversation with 3014 AI exchanges and confirmed smoother scrolling/rendering.
./script/runAgent Mode