perf(handler): eliminate repeated render scans and lookups - #496
Open
Mohamed Mansour (mohamedmansour) wants to merge 2 commits into
Open
perf(handler): eliminate repeated render scans and lookups#496Mohamed Mansour (mohamedmansour) wants to merge 2 commits into
Mohamed Mansour (mohamedmansour) wants to merge 2 commits into
Conversation
Precompute which inline style resources require closing-tag escaping when the Protocol loads, avoiding repeated CSS scans across component instances and requests while preserving unsafe CSS escaping. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f56ec396-84b4-4878-9eb5-18e420c8b723
Mohamed Mansour (mohamedmansour)
requested review from
Jane Chu (janechu) and
mcritzjam
and
a lite review from Copilot
August 27, 2026 00:02
Copilot started reviewing on behalf of
Mohamed Mansour (mohamedmansour)
August 27, 2026 00:03
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves handler render performance by caching which inline style resources require </style-escaping at Protocol load time, so safe CSS can be written directly without rescanning identical bytes on every render.
Changes:
- Added a protocol-owned
HashSetcache of style resources whose CSS contains a case-insensitive</stylesequence. - Updated the
<style>emission path to use the cached classification: write raw CSS for known-safe resources, and fall back to the existing escape writer for unsafe resources. - Introduced a shared detector (
style_text_needs_escape) and added tests for detector/writer parity and protocol cache classification.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/webui-handler/src/streaming/session.rs | Plumbs the protocol-owned escape cache into streaming render context initialization. |
| crates/webui-handler/src/streaming/inventory.rs | Updates streaming inventory test context initialization to include the new escape cache reference. |
| crates/webui-handler/src/route_handler.rs | Stores and builds the protocol-owned escape classification cache; adds a targeted unit test. |
| crates/webui-handler/src/lib.rs | Uses the cache to select raw vs escaped CSS writing; adds the cache field to the render context. |
| crates/webui-handler/src/html_encode.rs | Adds a fast </style detector shared by both the writer and the protocol classification; adds parity tests. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Reuse the immutable request-state lookup for dynamic component attribute output and child-scope capture instead of resolving the same path twice. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f56ec396-84b4-4878-9eb5-18e420c8b723
Mohamed Mansour (mohamedmansour)
requested a review
from Akrosh Gandhi (akroshg)
August 27, 2026 06:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Large component-list renders repeated two protocol-invariant or already-completed operations on the request hot path: identical inline CSS was rescanned for
</stylefor every instance, and state-backed dynamic component attributes resolved the same path once for HTML output and again for child-scope capture.What changed
Protocolloads.Architecture
Both optimizations remain inside
webui-handlerand preserve existing ownership boundaries. Runtime-only metadata stays on immutableProtocol, not the protobuf wire model. Attribute lookup reuse preserves the established precedence across loop bindings, borrowed locals, owned locals, and global state. No public API, protocol, rendering semantics, or dependencies change.Performance
Measured with:
cargo bench -p microsoft-webui --bench contact_book_bench -- 'contact_book_contacts_render/contacts/1000'The attribute lookup reuse alone improved the post-CSS-cache contact benchmark by 16.0% and the focused nested-component benchmark by 7.5%.
Validation
cargo xtask check