Jinja templates are from disk... we are blocking? #1583
-
PreambleTo avoid confusion this is NOT the same as "Asynchronous template rendering" here: https://www.starlette.io/templates/#asynchronous-template-rendering This is NOT an issue about separation of logic from templates. IssueUnless Jinja Jinja 3: https://github.com/pallets/jinja/blob/main/src/jinja2/environment.py#L1259 Starlette: https://github.com/encode/starlette/blame/master/starlette/templating.py#L37 DiscussionsPreviously: @tomchristie You mentioned:
Any new information here? More previously: Thank you for any insight! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Short: I've not seen enough evidence that a sync disk accesses are actually a significant benefit in practice. There's a bunch of overhead with the thread-pooling. Probably wouldn't want to act on this unless there was a compelling motivation. |
Beta Was this translation helpful? Give feedback.
-
@gnat if I am not mistaken, Jinja reads from disk only once and then caches template into a compiled function. So no intensive disk IO happens. Use |
Beta Was this translation helpful? Give feedback.
-
Great responses! Can confirm your comments are accurate as of this writing. Jinja's cache is a Environment settings for max performance:
With these set, I do also believe the benefit of May be a wise move to see these options noted in the deployment documentation @tomchristie because:
|
Beta Was this translation helpful? Give feedback.
Great responses! Can confirm your comments are accurate as of this writing.
Jinja's cache is a
{}
wrapped inLRUCache
to do automatic expiration. To prevent automatic expiration, Jinja overrides it to{}
: You just set the environment to negativecache_size=-1
setting seen here and hereEnvironment settings for max performance:
auto_reload=False
will prevent Jinja from checking timestamps on-disk if the template is already in the cache.cache_size=-1
will prevent Jinja from purging the cache. Safe if you have a set number of templates, otherwise a static value such ascache_size=10000
would be plenty; the Jinja default is400
.With these set, I do also believe the benefit of
async
would …