Eager load templates#57
Open
etiennebarrie wants to merge 2 commits into
Open
Conversation
Add FileSystemResolver#eager_load_templates, which globs the view path once and populates the unbound-template cache up front instead of lazily on first lookup. The cache stays mutable, so binding new locals at render time keeps working exactly as before; this only warms the cache. Also extract the lookup out of #_find_all into #unbound_templates_for and drop the throwaway Concurrent::Map that was allocated on every uncached lookup, computing directly instead.
Give Template, UnboundTemplate, the file source, and the resolver's PathParser a #freeze that turns them into deeply-frozen, Ractor-shareable objects, and add FileSystemResolver#freeze to freeze the whole eager-built cache. Combined with #eager_load_templates, a resolver can be built and then frozen so its templates can be shared across Ractors. Template#freeze memoizes the method name, strict-locals declaration and compiled source, then drops the compile mutex. UnboundTemplate collapses to a single @strict_locals_template once it discovers the template is strict, rather than a defaulting Hash, which makes freezing straightforward. Freezing requires strict locals: a non-strict template compiles a distinct method per set of locals, so it can't be reduced to one shareable template. UnboundTemplate#freeze therefore raises for any template that hasn't declared its locals. Support for freezing non-strict templates and partials is left to a follow-up.
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 gives a way to load all templates at boot time, and make them shareable.
For now only strict locals templates are supported, since they allow folding the
UnboundTemplate.@templatescache into a single Template object.