NAME
Catalyst::Seal::Dispatch - memoise the action lookups that stopped changing
DESCRIPTION
One action costs five forwards and six executes:
dispatch -> forward('/<ns>/_DISPATCH')
_DISPATCH -> forward each of _dispatch_steps, stopping on false
_BEGIN -> get_actions('begin', $ns), dispatch the last
_AUTO -> get_actions('auto', $ns), dispatch each
_ACTION -> $c->action->dispatch($c) <- the application's
_DISPATCH -> forward('_END') unconditionally
_END -> get_actions('end', $ns), dispatch the last
Each forward turns a string like '/steps/_BEGIN' into an action object, every request, for the life of the process: _command2action, _invoke_as_path, _action_rel2abs, get_action, get_action_by_path. The action table those walk is frozen at setup_finalize, so the answer is the same every time.
This module memoises the two lookups and nothing else.
Why the chain itself is not flattened
The plan for this phase was to compile the route table into C and run the chain as a flat loop. Measured, that is the wrong target twice over.
The lookup is not where the time is. prepare_action and DispatchType::Path::match are about 11 us per request; the chain walk is about 29. A trie would make an already cheap hash lookup marginally cheaper.
And the chain cannot be flattened without reimplementing execute. The private steps go on $c->stack, and that stack is load bearing: $c->depth is scalar @{$c->stack}, Catalyst::Exception::Detach rethrows only if $c->depth > 1, Go only if $c->depth > 0, and an uncaught error names $last->class and $last->name off it. A flat chain that skips the pushes turns a depth of 3 into a depth of 1, and a detach from an action stops rethrowing. Preserving the stack means doing execute's push, pop, depth guard, stats check, eval and error handling five times over, in this distribution, which leaves about 5 us of forward and _do_forward as the entire prize.
Memoising the lookups gets most of the recoverable time for none of that risk, so that is what this does. The arithmetic is in plan_catalyst_seal/phase_5_TODO.md.
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)