Repository navigation
Conversation
When templates aren't cached, the engine emptied the compile cache before every request, so every request recompiled every component it rendered, even when nothing changed. Like Action View does for views, watch the templates and translation files in the autoload paths with config.file_watcher, and only invalidate the cache when one of them is added, changed, or removed. Changes to Ruby files reload the application, which clears the cache.
This branch has not been deployed
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.
Closes #2729
What are you trying to accomplish?
When templates aren't cached, which is the default in development, the engine empties the compile cache before every request, so every request recompiles every component it renders, even when no template changed. This only invalidates the cache when a template or a translation file was added, changed, or removed.
On our app (between 43 and 60 components per page), median of 7 requests after a warm-up:
What approach did you choose and why?
The same one as Action View's
ActionView::CacheExpiry::ViewReloaderfor views: aconfig.file_watcherover the autoload paths, since components can live outsideapp/componentsand in engines, watchingActionView::Template::Handlers.extensionsplusymlandyamlfor sidecar translations. Changes to Ruby files, inline templates included, already reload the application, so the cache is also cleared onbefore_class_unload.The watcher is built on the first request that doesn't cache templates, so the template handlers registered by gems like Slim or Haml are known by then, and
ActionView::Base.cache_template_loadingis still checked on every request, as the test helpers toggle it.Anything you want to highlight for special attention from reviewers?
The existing tests for template changes being reflected on the next request fail if the watcher doesn't invalidate the cache, so they cover the change. I added one checking that a component isn't recompiled when no template changed, which fails on
main, and one for an added template.