Skip to content

perf(terminal): O(1) is_any_ai_block_focused via ancestor set#13113

Open
acarl005 wants to merge 1 commit into
andy/long-convo-latency-exchange-lookupfrom
andy/long-convo-latency-block-focus-optimization
Open

perf(terminal): O(1) is_any_ai_block_focused via ancestor set#13113
acarl005 wants to merge 1 commit into
andy/long-convo-latency-exchange-lookupfrom
andy/long-convo-latency-block-focus-optimization

Conversation

@acarl005

@acarl005 acarl005 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Description

Part of a stack of performance fixes for #9799.

This PR: is_any_ai_block_focused in terminal/view.rs was called on every render of a terminal view that contains AI blocks. It iterated all N AI block IDs and called is_self_or_child_focused on each, which internally called view_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_ancestors once into a HashSet<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

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).

Testing

Manually loaded a conversation with 3014 AI exchanges and confirmed smoother scrolling/rendering.

  • I have manually tested my changes locally with ./script/run

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

acarl005 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@oz-for-oss

oz-for-oss Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

@acarl005

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 /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@acarl005 acarl005 force-pushed the andy/long-convo-latency-block-focus-optimization branch from bc7cbbe to f9f0193 Compare June 26, 2026 23:49
@acarl005 acarl005 force-pushed the long-convo-latency-restore-blocks-stage branch from 35dacbd to 3fd5226 Compare June 26, 2026 23:49
@acarl005 acarl005 force-pushed the andy/long-convo-latency-block-focus-optimization branch from f9f0193 to e5d6e80 Compare June 27, 2026 00:15
@acarl005 acarl005 force-pushed the long-convo-latency-restore-blocks-stage branch 2 times, most recently from 07b7b3b to cc6d905 Compare June 27, 2026 01:21
@acarl005 acarl005 force-pushed the andy/long-convo-latency-block-focus-optimization branch from e5d6e80 to bcecab0 Compare June 27, 2026 01:21
@acarl005 acarl005 changed the base branch from long-convo-latency-restore-blocks-stage to graphite-base/13113 June 27, 2026 02:13
@acarl005 acarl005 force-pushed the andy/long-convo-latency-block-focus-optimization branch from bcecab0 to e0445ff Compare June 27, 2026 02:13
@acarl005 acarl005 force-pushed the graphite-base/13113 branch from cc6d905 to 75061d8 Compare June 27, 2026 02:13
@acarl005 acarl005 changed the base branch from graphite-base/13113 to andy/long-convo-latency-exchange-lookup June 27, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant