Engine: Precompile Action View Tag Helpers#1613
Draft
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 |
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 precompilation support for Action View tag helpers to the
Herb::Engine.When
precompile: 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 precompilation is 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_precompiled_output_matchhelper that validates precompiled output against both standard Herb and ActionView+Erubi to assure 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 precompilation 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.
Resolves #653
Enables #1111