Skip to content

Add support for caching in build step#99

Open
joelhawksley wants to merge 6 commits into
marcoroth:mainfrom
joelhawksley:cache
Open

Add support for caching in build step#99
joelhawksley wants to merge 6 commits into
marcoroth:mainfrom
joelhawksley:cache

Conversation

@joelhawksley
Copy link
Copy Markdown
Contributor

Context

As documented in #96, we have observed a significant increase in ERB compilation overhead, which we see at boot time when using https://github.com/jhawthorn/actionview_precompiler and when ViewComponents compile their templates. On a test production deployment, we saw boot-time template precompilation jump from ~15s to nearly a minute, an unacceptable overhead to pay every time we boot a container.

Proposed solution

This PR adds a reactionview:precompile rake task that compiles all files covered by the Herb configuration inclusion/exclusion rules. If config.cache = true, the compiled cache is used, skipping the work of compiling ERB to Ruby. In a test production deployment we saw equivalent boot-time precompilation times in the 15s range.

If this change is generally deemed acceptable, I'd be happy to add docs to this PR.

Alternatives considered

Add cache to ActionView::Precompiler

I wrote jhawthorn/actionview_precompiler#46 (cc @jhawthorn) and deployed it to a lab environment with good results. However, the optimization is really only necessary for Herb, so adding the complexity there felt like a bit much.

Add cache to Herb

I wrote https://github.com/marcoroth/herb/compare/main...joelhawksley:herb:cache?expand=1 to add a cache to Herb instead. Unfortunately, ReActionView configures Herb with specific options which resulted in the cache not being hit.

Further opportunities

In a preliminary benchmark, I tried compiling to Ruby instruction sequences, resulting in performance faster than Erubi. I did not include this change here in order to keep things simple.

References

Closes #96

@marcoroth
Copy link
Copy Markdown
Owner

Thank you @joelhawksley! 🙏🏼

I want to be transparent here: I'll be at RubyKaigi next week and just added a mental note for this PR. I will get back to you after the conference, especially because I have some ideas I want to discuss with people to see if we actually need something like this. I'll keep you posted 🙌🏼

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Impact on cold render performance

2 participants