Skip to content

Engine: Precompile Action View Tag Helpers#1613

Draft
marcoroth wants to merge 29 commits intomainfrom
precompile-action-view-helpers
Draft

Engine: Precompile Action View Tag Helpers#1613
marcoroth wants to merge 29 commits intomainfrom
precompile-action-view-helpers

Conversation

@marcoroth
Copy link
Copy Markdown
Owner

@marcoroth marcoroth commented Apr 5, 2026

This pull request adds precompilation support for Action View tag helpers to the Herb::Engine.

When precompile: 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 precompilation is 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_precompiled_output_match helper 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 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 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.

CleanShot 2026-04-05 at 23 58 07@2x

Resolves #653

Enables #1111

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 5, 2026

npx https://pkg.pr.new/@herb-tools/formatter@1613
npx https://pkg.pr.new/@herb-tools/language-server@1613
npx https://pkg.pr.new/@herb-tools/linter@1613

commit: 985c3f7

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit 985c3f7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Engine: Optimize Action View Tag Helpers when compiling template

1 participant