Hi,
I ran some Jinja2 benchmarks using the precompiled templates vs.
non-compiled vs. using bytecode cache. This was the average time to
render a simple template (some blocks, a few includes, 5 template
files in total, Environment was created on each iteration):

Non-compiled: 0.0679 sec
Precompiled: 0.0052 sec
BytecodeCache: 0.0018 sec

While precompiled templates are 13 times faster than non-compiled
ones, they are still 3 times slower than when we use bytecode cache
(take these number as illustrations, the benchmark was not
scientific). This is due to the exec used to run the generated code, I
guess.

So I experimented loading the precompiled templates as a module, and
(surprise!), they were consistently 3 times faster than using bytecode
cache:

templates as modules: 0.0006 sec

This is blazing fast. However, I had to hack how Jinja2 generates the
Python code, so that a precompiled template could be imported. The
generated functions expect environment to be present in the module,
and environment is defined in the namespace during exec in
Template.from_code(). Now my lack of Python knowledge strikes, as I
could not import the generated code while inserting the required
environment variable (I asked in #python, and they said it is not
possible :P). So I added a "lazy" environment variable to the
generated code (hacking jinja2.compiler).

So, what you think about wrapping the generated code by a function,
and call the function passing environment and whatever other
parameters are needed in Template.from_code()? Or whatever other
method to make the environment variable 'injectable' without exec
(allowing the code to be imported)? Do you think  'templates as
modules' make sense and can be supported?

I hope this makes sense and I am not missing anything. :-)

regards,
-- rodrigo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to pocoo-libs@googlegroups.com
To unsubscribe from this group, send email to 
pocoo-libs+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to