Hi,
I've compiled the django.template.{base,context,context_processor} modules with cython in order to speed up template rendering.
I've come to the conclusion that this is needed after profiling long page loads that had the data from the database returned in 10-50 ms,
but the page would take seconds to complete - especially admin change views with lots of inlines.
I am seeing a 13% decrease in page rendering time across the board, obviously passing all django tests.
To make this easy to deploy I've compiled it as a drop-in replacement (targeting django 1.8.7) that uses import hooks (PEP 302)
to replace targeted modules on the fly.
The sources/releases are here: https://github.com/ddalex/django-cemplate
Can you please advise on how to continue this work ?
I feel that maintaining separate trees for each Django release is not scalable on my part.
HI Alex,On Wed, Dec 9, 2015 at 9:57 PM, Alexandru Damian <dda...@gmail.com> wrote:Hi,
I've compiled the django.template.{base,context,context_processor} modules with cython in order to speed up template rendering.
I've come to the conclusion that this is needed after profiling long page loads that had the data from the database returned in 10-50 ms,
but the page would take seconds to complete - especially admin change views with lots of inlines.If you’re seeing admin pages taking *seconds* to render, and the database is truly taking 10-50ms, there’s something going *very* wrong here. Can you share your profile data?
I am seeing a 13% decrease in page rendering time across the board, obviously passing all django tests.Have you tried running PyPy instead? The reports I’ve seen suggest you’ll get a *lot* more than a 13% speedup.
To make this easy to deploy I've compiled it as a drop-in replacement (targeting django 1.8.7) that uses import hooks (PEP 302)
to replace targeted modules on the fly.
The sources/releases are here: https://github.com/ddalex/django-cemplate
Can you please advise on how to continue this work ?
I feel that maintaining separate trees for each Django release is not scalable on my part.It’s difficult to say without knowing what you’re proposing. Is there some change you’d like to see merged into Django? Some API hook that you’d like to add to make your life easier?
Yours,Russ Magee %-)
I am thinking of cythonizing parts of django (e.g. the modules that I am modifying here) - this will bring .c compilation on install, but will make code faster in the framework, where it is likely that nobody is modifying it. It brings in an extra dependency on cython for developers. What is your take on this ?
I cProfile-instrumented def get_response() in django/core/handlers/base.py without (vanilla django) and with cemplate, posted the results here:
Both profiles are with all caches primed. Please compare time spent in django/template/base.py in vanilla (0.773 seconds) and cemplate (0.288) seconds.
Can you please advise on how to continue this work ?
I feel that maintaining separate trees for each Django release is not scalable on my part.It’s difficult to say without knowing what you’re proposing. Is there some change you’d like to see merged into Django? Some API hook that you’d like to add to make your life easier?
Hi Alexandru,
On Thursday, December 10, 2015 at 12:52:46 PM UTC+1, Alexandru Damian wrote:I cProfile-instrumented def get_response() in django/core/handlers/base.py without (vanilla django) and with cemplate, posted the results here:
The results are odd, looks as if you are running in a "test"-like environment. Please make sure you run them with DEBUG=False and without any test instrumentation to mimic a production environment.
Both profiles are with all caches primed. Please compare time spent in django/template/base.py in vanilla (0.773 seconds) and cemplate (0.288) seconds.
Yeah, that is roughly a 100% speedup in template rendering (does one say 100% if twice as fast?!)
Can you please advise on how to continue this work ?
I feel that maintaining separate trees for each Django release is not scalable on my part.It’s difficult to say without knowing what you’re proposing. Is there some change you’d like to see merged into Django? Some API hook that you’d like to add to make your life easier?
I am not really convinced that replacing the whole file is a good idea. In my experience one gets better results when using Cython by strategically replacing single functions and rewriting those in C directly.
A factor of two is all nice an well, but if this is still just 10% in the overall response there might be other (better) optimizations out there.
Cheers,
Florian
I am not really convinced that replacing the whole file is a good idea. In my experience one gets better results when using Cython by strategically replacing single functions and rewriting those in C directly.
This is the actual approach I am taking, but at class level. I selectively choose the base classes and convert those to Cython language; the modules are packaged in as a whole to make packaging easier.