Commit ceaffa4
authored
Engine: Compile-time optimizations for Action View tag helpers (#1613)
This pull request adds compile-time optimization support for Action View
tag helpers to `Herb::Engine`.
When `optimize: true` is passed to `Herb::Engine`, the parser transforms
Action View helper calls (`tag.*`, `content_tag`, `link_to`,
`image_tag`, `javascript_tag`, `javascript_include_tag`,
`turbo_frame_tag`) into their HTML equivalents at compile time,
producing optimized Ruby output that avoids runtime helper dispatch.
When compile-time optimizations are enabled, the engine checks whether
the template contains supported Action View helpers via the
`Herb::ActionView::HelperRegistry.supported` method. If helpers are
detected, the parser is invoked with `action_view_helpers: true` and
`transform_conditionals: true`, which also handles postfix if/unless and
ternary conditionals containing helper calls.
The pull request also includes comprehensive snapshot-based tests for
all supported helpers, an `assert_optimized_output_match` helper that
validates optimized output against both standard Herb and
ActionView+Erubi to ensure the rendered output matches.
Additionally, we added a YAML-driven benchmark framework in
`bench/action_view/` with a `bin/bench` CLI for compile-time and
render-time comparisons. Early benchmarks show render-time improvements
of 3-22x depending on the template, with a realistic 192-line page
layout rendering 22x faster, and a helper-heavy template with all static
values reaching up to 150x faster.
The trade-off is compile time: Herb's parser is currently 10-90x slower
than Erubi at compile time, so optimization adds overhead that needs to
be amortized over multiple renders. But this is typically won back with
15-100 renders depending on template complexity and could also be done
ahead of time, instead of the current on-the-fly approach used in Action
View today.
> [!WARNING]
> Compile-time optimizations are experimental. Output may differ from
standard ActionView rendering.
<img alt="CleanShot 2026-04-05 at 23 58 07@2x"
src="https://github.com/user-attachments/assets/da407b38-e101-47e9-96a7-b58ed36fdf9d"
/>
Resolves #653
Enables #11111 parent 2a9d977 commit ceaffa4
263 files changed
Lines changed: 3645 additions & 244 deletions
File tree
- bench/action_view
- benchmarks
- bin
- javascript/packages/rewriter/test
- lib
- herb
- engine
- html
- sig
- herb
- engine
- html
- src/analyze/action_view
- test
- engine
- action_view
- html
- snapshots
- analyze/action_view/tag_helper/tag_test
- engine
- action_view
- content_tag_test
- image_tag_test
- javascript_include_tag_test
- javascript_tag_test
- link_to_test
- postfix_conditional_test
- tag_attributes_test
- tag_test
- ternary_conditional_test
- turbo_frame_tag_test
- evaluation_test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| 98 | + | |
| 99 | + | |
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
| |||
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
| 119 | + | |
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
| |||
145 | 150 | | |
146 | 151 | | |
147 | 152 | | |
| 153 | + | |
148 | 154 | | |
149 | 155 | | |
150 | 156 | | |
| |||
177 | 183 | | |
178 | 184 | | |
179 | 185 | | |
| 186 | + | |
180 | 187 | | |
181 | 188 | | |
182 | 189 | | |
| |||
192 | 199 | | |
193 | 200 | | |
194 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
49 | 59 | | |
50 | 60 | | |
51 | 61 | | |
| |||
67 | 77 | | |
68 | 78 | | |
69 | 79 | | |
| 80 | + | |
70 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
71 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
72 | 114 | | |
73 | 115 | | |
74 | 116 | | |
| |||
95 | 137 | | |
96 | 138 | | |
97 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
98 | 151 | | |
99 | 152 | | |
100 | 153 | | |
101 | 154 | | |
102 | 155 | | |
103 | 156 | | |
104 | 157 | | |
105 | | - | |
| 158 | + | |
106 | 159 | | |
107 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
108 | 167 | | |
109 | 168 | | |
110 | 169 | | |
111 | 170 | | |
112 | 171 | | |
113 | | - | |
| 172 | + | |
114 | 173 | | |
115 | 174 | | |
116 | 175 | | |
| |||
120 | 179 | | |
121 | 180 | | |
122 | 181 | | |
123 | | - | |
| 182 | + | |
124 | 183 | | |
125 | | - | |
| 184 | + | |
126 | 185 | | |
127 | | - | |
| 186 | + | |
128 | 187 | | |
129 | | - | |
| 188 | + | |
130 | 189 | | |
131 | | - | |
| 190 | + | |
132 | 191 | | |
133 | | - | |
| 192 | + | |
134 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
135 | 200 | | |
136 | 201 | | |
137 | 202 | | |
| |||
145 | 210 | | |
146 | 211 | | |
147 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
148 | 221 | | |
149 | 222 | | |
150 | 223 | | |
151 | 224 | | |
152 | | - | |
153 | | - | |
| 225 | + | |
| 226 | + | |
154 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
155 | 237 | | |
156 | 238 | | |
157 | 239 | | |
| |||
167 | 249 | | |
168 | 250 | | |
169 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
170 | 255 | | |
171 | 256 | | |
172 | 257 | | |
| |||
195 | 280 | | |
196 | 281 | | |
197 | 282 | | |
| 283 | + | |
198 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
199 | 288 | | |
200 | 289 | | |
201 | 290 | | |
202 | 291 | | |
203 | 292 | | |
204 | 293 | | |
| 294 | + | |
| 295 | + | |
205 | 296 | | |
206 | 297 | | |
207 | 298 | | |
| |||
216 | 307 | | |
217 | 308 | | |
218 | 309 | | |
| 310 | + | |
| 311 | + | |
219 | 312 | | |
220 | 313 | | |
221 | 314 | | |
| |||
229 | 322 | | |
230 | 323 | | |
231 | 324 | | |
| 325 | + | |
232 | 326 | | |
233 | 327 | | |
234 | 328 | | |
235 | 329 | | |
| 330 | + | |
236 | 331 | | |
237 | 332 | | |
238 | 333 | | |
0 commit comments