Jinja2 Rocks!

Jinja2 is an awesome templating system! I've always been happy with the builtin templating framework in Django until about a week ago when I needed to render large amounts of tabular data. Then the Django templating system more or less breaks down because the rendering takes over 2 - 300 milliseconds which is to much time.

My first solution was to aggressively cache rendered pages using the cache middleware. Unfortunately that makes it hard to keep data changes in sync with what visitors see on the site. Plus, the first time the page is accessed is still slow.

The real solution was to throw out the old Django templates and start to learn Jinja2. It's not done yet, but I'm getting there. Meanwhile, here is a performance test that shows how much superior Jinja2 is:

# First the Jinja2 variant from jinja2 import Template from time import time t = Template(''' {% for obj in objs %} <tr> <td>{{ obj.x }}</td> <td>{{ obj.y }}</td> <td>{{ obj.x }}</td> <td>{{ obj.y }}</td> </tr> {% endfor %} ''') class O: x = 3.4 y = 2.5 objs = [O() for x in range(350)] s = time() for x in range(10): print t.render(objs = objs) print (time() - s) / 10.0 # Then Django templates. from django.template import Context, Template from time import time t = Template(''' {% for obj in objs %} <tr> <td>{{ obj.x }}</td> <td>{{ obj.y }}</td> <td>{{ obj.x }}</td> <td>{{ obj.y }}</td> </tr> {% endfor %} ''') class O: x = 3.4 y = 2.5 objs = [O() for x in range(350)] c = Context({'objs' : objs}) s = time() for x in range(10): t.render(c) print (time() - s) / 10.0

Warning for WebFaction

UPDATEAs you can see, this blog post is more than a year old. Since then Webfaction's servers performance has improved considerably. Their support is also much more pleasant to deal with so today I would consider them a pretty decent hoster.

There are lots of great, professional hosting companies out there. Most of them are qualified for what they do and provides exactly the service you're paying for.

WebFaction is not one of them.

The question is what can you expect for $8.50 per month plus VAT? Maybe not a whole lot, and maybe I'm expecting to much. When I signed up, it was to host my GtkImageView project which I'm still keeping at them, but I'm getting increasingly frustrated with them and will migrate before the year runs out if time permits.

What is promised on their site is the ability to run Trac and Subversion which is exactly what I need. Though when it takes over ten seconds to load a single page, thanks to congestion on their servers and overselling, then that is not ok! It is worse than ok because it gives the impression that something should work decently when in reality it sucks majorly. If you don't believe me, then try checking out GtkImageView using Subversion. It is sloooooow.

In the future, I will likely move GtkImageView to some other hosting provider. Possibly to GNOME:s infrastructure if they want to host it. I think they can do a much better job than me, because dealing with hosting related issues is much more work than it seems. Or maybe to Google Code, fast and efficient.

Anyway, I sincerely want to anti-recommend WebFaction. You will be disappointed.