Jinja2 vs django templates with cached loader - how does performance compare?

I'm curious - with the introduction of the cached template loader in django 1.2, how does performance compare with the latest Jinja2?

Has anyone tried to run tests?

Thanks.

+4
source share
2 answers

Jinja is more pythonic (more flexible) and maybe faster than the Django templating system, but performance especially depends on your dev skill and other parameters.

As explained in the Jinja FAQ:

http://jinja.pocoo.org/docs/faq/#how-fast-is-it

0
source

This is a good question, but a false dichotomy, since you can use Django cached.Loader and pass Jinja Loaders to it to have cached Jinja templates.

Secondly, template caching is not only speed. I would recommend a cached loader when DEBUG = False, so you can easily iterate over templates during development, but a cached loader is important for production, because without caching, your templates may not synchronize with your code for some period of time, deployment.

For example, let's say you change the context of the view and update the template, as well as commit. Now, if you pull git, and then restart the server, the time between git pulling and restarting, the view will be 500, because you are serving a new template with old code. If you receive multiple requests per second, this will lead to the production of the 500s, unless your production deployment method deceives it using multiple directories.

0
source

All Articles