Skip to content

Each pump class resolves which scopes serve a message type once, not per message - #253

Open
trissim wants to merge 1 commit into
mainfrom
perf/conventional-handlers-compiled
Open

trissim wants to merge 1 commit into
mainfrom
perf/conventional-handlers-compiled

Conversation

@trissim

@trissim trissim commented Nov 6, 2026

Copy link
Copy Markdown

Author: claude-b-ui (patch applied with git am, authorship kept). Every message walked the receiver's whole MRO and asked each class for routes and an _on_x/on_x entry (81.7M conventional_methods calls in Toad's suite profile). DispatchScope.compiled(message_type) answers each scope's part once; MessagePump._compiled_scopes keeps the non-empty CompiledScopes in C3 order per class and message type. The test-only 'live dictionary' mutation contract is deleted (no caller in Textual or Toad).

b-ui's proof: Textual on/message/pump/binding/focus/signal/navigation 156 passed (1 pre-existing failure on main: test_message_inheritance_namespace); Toad keymap 22 passed. Per message: 10.27 -> 9.90 us (-3.6%).

🤖 Generated with Claude Code

https://claude.ai/code/session_01XbFMSqJMarXn2ZE8iAL7Sd

…per message

Every message walked the receiver's whole MRO and asked each class for routes and for an
`_on_x`/`on_x` entry (claude-a-toad's suite profile: 81.7M conventional_methods calls).
Which routes and which conventional handler a class declares for a message type is fixed
once the class exists, so DispatchScope.compiled(message_type) answers this scope's part,
or nothing, and MessagePump._compiled_scopes keeps the non-empty CompiledScopes in C3
order per class and message type. Message._dispatch_scopes and the DeclaredMessage binding
read those. Selector matching and _no_default_action stay per message.

Private-name precedence and a decorated private entry masking the public one are kept in
NamedScope.conventional_entries. The "live dictionary" the old lookup preserved had no
caller in Textual or Toad source; only test_on.py replaced a handler on the class in the
middle of dispatch, so that assertion goes and the test keeps the dispatch order.
CompiledScope and BoundScope share RoutedScope, which owns a narrowed routes tuple.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XbFMSrQKHwQJSkZZaLyQha
Copilot AI balanced review requested due to automatic review settings November 6, 2026 15:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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.

3 participants