Two Wrongs

(don't make a right)

What Optimisations Are Not

by ~kqr

While searching for something completely different, I came across an interesting question on StackOverflow about unexpected behaviour from the Django Template Language. Under some circumstances, the DTL processor will perform a side-effectful action even if the user has asked it not to do that.

For performance reasons, the DTL processor greedily includes all low-hanging templates (in other words, those that are easy to figure out which they are) without regard for whether or not they should be included. Then at a later stage, some of them can get "unincluded" if the user has asked the DTL processor to not include them. The official name for this feature-slash-bug is that it's an "optimisation".

I'll tell you what – it's not an optimisation.

An optimisation is a change that does not under any circumstance visibly change the behaviour of something that is written according to specification, other than making it run faster, consume less memory or something of the kind. Since the DTL feature clearly can change the behaviour of a valid program (to the point where it crashes!) it's not an optimisation.

I'm sure there are good reasons to keep it in there, though. I'm sure it gives a massive increase in processing speed when it comes to include-heavy templates. But don't call it an optimisation.

If you enjoyed this article, you might like others tagged with