Engine: Compile-time optimizations for Action View tag helpers#1613
Merged
Engine: Compile-time optimizations for Action View tag helpers#1613
Conversation
commit: |
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
marcoroth
added a commit
that referenced
this pull request
Apr 20, 2026
This pull request adds `framework` and `template_engine` configuration options to the `.herb.yml`. These top-level settings tell Herb what environment it's running in and what template engine is being used for compilation. This enables context-aware behavior across the toolchain. Configuration in `.herb.yml`: ```yml framework: actionview # ruby | actionview | hanami | sinatra (default: ruby) template_engine: herb # erubi | erb | herb (default: erubi) ``` Valid values are defined once in `config/options.yml` and code-generated into the relevant configuration files in all bindings. This allows us in the future to have more specific features tailored for each target framework and engine. This pull request is meant to lay the groundwork for: - Framework-aware linter rules, so that we can automatically enable/disable rules based on the framework (see #480) - Framework-aware compile-time optimizations. Knowing the framework context determines which helpers are available for optimization (like #1613) - Template engine compatibility, surfacing invalid syntax or other target engine's conventions across the toolchain (for example no ERB block support)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds compile-time optimization support for Action View tag helpers to
Herb::Engine.When
optimize: trueis passed toHerb::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.supportedmethod. If helpers are detected, the parser is invoked withaction_view_helpers: trueandtransform_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_matchhelper 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 abin/benchCLI 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.
Resolves #653
Enables #1111