Commit cb50d5f
Replace per-request Proc in Router#transaction with a helper method
The `cascade_or_return_response` proc inside `Router#transaction` was
allocated on every request because it relied on non-local `return` to
exit the enclosing method when a non-cascading response arrived. That
behavior was doing two things at once — closing the cascading body as
a side effect, and halting transaction processing.
Split them: a plain `halt?(response)` helper returns `true` when the
response is final (and should be returned as-is), `false` when it's
either absent or cascading; closing the body lives inside the helper
as a side effect. The `transaction` method then uses explicit
early-returns for the halt case and plain assignments for the cascade
flag.
current variant speedup alloc
cascading response 3.12 M/s 6.88 M/s 2.21x 1 → 0 objects
hit response (final) 3.07 M/s 9.82 M/s 3.20x 1 → 0 objects
nil response 5.07 M/s 15.7 M/s 3.10x 1 → 0 objects
Saves one proc allocation per request in the router's `transaction`
dispatch — plus 2–3x faster control flow in the cascade-decision step.
No behavior change; all 2,236 specs pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent f2ef861 commit cb50d5f
2 files changed
Lines changed: 21 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | 106 | | |
119 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
120 | 110 | | |
121 | 111 | | |
122 | 112 | | |
| |||
127 | 117 | | |
128 | 118 | | |
129 | 119 | | |
130 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
131 | 126 | | |
132 | 127 | | |
133 | 128 | | |
134 | 129 | | |
135 | 130 | | |
136 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
137 | 143 | | |
138 | 144 | | |
139 | 145 | | |
| |||
0 commit comments