Skip to content

MroDispatch resolves a value type's handlers once - #12

Merged
trissim merged 1 commit into
mainfrom
mro-dispatch-resolves-once
Nov 13, 2026
Merged

trissim merged 1 commit into
mainfrom
mro-dispatch-resolves-once

Conversation

@trissim

@trissim trissim commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

What changes

MroDispatch.handler_names_for walked the value type's whole MRO against every @handles declaration on each call. Both sides are fixed when their classes are created, so the join is now resolved once per (consumer class, value type) and every dispatch reads it (resolved_handler_names). Each consumer class gets its own table in __init_subclass__, so a subclass that adds a handler never reads its parent's answers.

handler_names_for, handler_for and handlers_for keep their signatures and results.

Numbers

agent-comms dispatches every streamed Pi event through about ten MroDispatch consumers. Resolving MessageUpdate (MRO depth 13) on each of its 697 consumer classes, 2,000 calls each:

mean per call a 6-handler consumer (DurableTurn)
main 1.6 µs 2.6 µs
this branch 0.4 µs 0.7 µs

That is roughly 30 ms of a one-message burst in agent-comms: small, and correct to remove.

Tests

tests/test_mro_dispatch.py: 10 passed. One new test: a subclass declared after its parent has already resolved a type still gets its own handlers, and the parent does not see them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XbFMSnLEc51gw21bLFFRK1

handler_names_for walked the value type's MRO against every @Handles declaration
on each call. A consumer's declarations and a value type's MRO are fixed at class
creation, so the pair is resolved once and every dispatch reads it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XbFMSnLEc51gw21bLFFRK1
@trissim
trissim merged commit 1ad09c8 into main Nov 13, 2026
10 checks passed
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.

1 participant