Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django template includes slow?

Should I be trying to minimize template includes? I've been using them somewhat liberally but am wondering if they are inefficient or add some overhead in rendering templates?

In some cases I have templates that include templates which include other templates.

like image 738
9-bits Avatar asked Feb 27 '12 01:02

9-bits


1 Answers

Template rendering time is normally much smaller than database time in especial, so typically you don't need to worry about it early on; there are other regions where performance can be increased more effectively.

For deployment, you can usually increase the performance of template inclusions by using the cached loader (you may need to scroll down a bit). Then it only loads templates once and thereafter it can use the compiled template instead of needing to load it from disk.

To address the question of template rendering overhead, once you've got it cached, it's quite cheap. I wouldn't worry about it at all. Do it in such as way as to maximise the maintainability of your system.

It would probably be irresponsible of me to not mention (hopefully, remind you of) two adages of performance optimisation; they are common enough sayings that you should be able to find plenty of information on them if you are not familiar with them.

  1. Don't optimise prematurely.
  2. Measure—don't guess.
like image 139
Chris Morgan Avatar answered Oct 20 '22 08:10

Chris Morgan