I'm working on a project that needs to occasionally render very large tables -- I'm picking hundreds of thousands of cells as a test point for trying out back end implementation scalability.
I'm parallelizing some of the rendering through ajax calls that returns large subsets of the rendered cells ("<td class='foo'>content</td>") within a JSON structure. I'm using a short template to render each cell:
template = get_template('cell.djhtml')
for datapoint in self._iterate_datapoints():
datapoint_cell[datapoint.foo_id][datapoint.bar_id] = template.render(dict(datapoint=datapoint))
If I change the template.render() call to just a "<td class='score'>%s</td>" % datapoint.score, the code is an order of magnitude faster.
My assumption (and my reading of the django code I think confirmed) that the template is compiled only once, so I'm ok there.
Is this difference surprising or unexpected? Would a single (consolidated) render() be expected to be much faster? (I'm trying to think of a way to refactor it to a single render, but I'm not looking forward to rendering json in a django template)
I'm also considering I may just need to return structured json and create the elements manually on the client side -- although if I have to do it that manually, I might as well use interpolation on the backend python without using a template...
Oh, and I just tried jinja2 -- it was much closer to interpolation speed. Perhaps that is my best answer.
Any thoughts or pointers on my predicament?
Thanks!
Rich