5 ms·
In Python versions older than 2.6 and on Google appengine it's the only reliable way to generate bytecode. For things like template engines this is important t
by the_mitsuhiko 16y ago
In Python versions older than 2.6 and on Google appengine it's the only reliable way to generate bytecode. For things like template engines this is important to not add extra overhead over an already slow language.
- IgorPartola 16y agoThat seems like a terrible approach to me. If your application's bottleneck is in parsing templates, either everything else is really fast or you have way too many complex templates. Maybe caching is a better strategy in that case. Then again, for a variety of reasons I have decided not to touch GAE if I can help it.
- the_mitsuhiko 16y ago> If your application's bottleneck is in parsing templates, either everything else is really fast or you have way too many complex templates. There are countless of examples where the template engine is the bottleneck of an application. If you are doubting that, I welcome you to try it yourself. Benchmarking Django's templates and Genshi is an eye opening experience. :)
- m0th87 16y agoProof is in the pudding. Where's the pudding? :) From a quick google search, they seem pretty comparable. And in fact Django oftentimes wins. http://genshi.edgewall.org/wiki/GenshiPerformance http://genshi.edgewall.org/wiki/GenshiPerformance http://stackoverflow.com/questions/1324238/what-is-the-fastest-template-system-for-python http://stackoverflow.com/questions/1324238/what-is-the-faste...
- the_mitsuhiko 16y agoNever trust a benchmark you didn't run yourself. A realistic Genshi template is butt slow. More than a handful function calls per byte emitted is not uncommon. Regarding Django it become a lot slower when they introduced automatic escaping and loop item unpacking a while ago. I have seen many people switching from Django templates to Jinja2 especially because of the increased performance.
- thezilch 16y agoI believe Mitsuhiko was trying to draw comparisons of Django or Genshi engines to those of Jinja2 or Mako. There was a well depicted article, year(s) back, showing (profiling) where Django templating was losing a lot of work, compared to Jinja. Unfortunately, the article appears to have fallen off pocoo.org, but you can find the HN discussion at the following: http://news.ycombinator.com/item?id=726461 http://news.ycombinator.com/item?id=726461
- m0th87 16y agoI don't see it as so much of a performance issue as a usability issue. Tornado uses eval for parsing templates. The nice effect of this is that you write Python snippets in your templates rather than learning an entirely new DSL for it (like in Django). It's pretty nice as long you're disciplined enough to not put business logic in the templates.
- IgorPartola 16y agoEek. Sorry, I disagree. IMHO, templating engines should not allow you to do much more than simple substitution, loops and escaping. I think Django strikes a very nice balance and learning to use it takes minutes. This is like saying that you should be allowed to use ASM in your Python code, as long as you promise never to actually do it.
- m0th87 16y agoSay what you will, but I find my Tornado templates much less verbose than in Django, even when respecting the rules of "proper" templating. Also, I just realized you're my former coworker. Hi Igor, it's Yusuf :)
- IgorPartola 16y agoSmall world!
- thezilch 16y agoTerrible how? I find frameworks are more than welcome to make use of optimizations that are not going to have ill effects on the user. For example, I've yet to find fault in Jinja2's ability to use bytecode-cached templating. How do you define complex templates? And as Mitsuhiko has pointed out, it is not just a problem with GAE.
- IgorPartola 16y agoBy complex I mean templates that make your templating engine go slow. Unless you are using a terrible engine, which is slow no matter what it's parsing.
- thezilch 16y agoPerhaps you need to define slow or run the benchmark(s) yourself. Sorry to be pedantic. I don't really understand what you mean by "templates that make your template engine go slow," as business requirements are going to trump anyones' skewed, dogmatic reality on the [controlled] use of eval, exec, etc. Where my data is coming from local cache, the template does stick out in the request/response chain.
- IgorPartola 16y agoPedantic is fine. I mean templates so complex as to become a bottleneck in processing web requests (rendering the template takes more time than any other operation performed). http://en.wikipedia.org/wiki/Bottleneck#Bottlenecks_in_software http://en.wikipedia.org/wiki/Bottleneck#Bottlenecks_in_softw.... In your scenario, if you can cache the data, you can likely cache rendered templates, or parts of the rendered templates, or introduce a caching reverse proxy.