Support ⇒ Designer Dragonfly v10 ⇒ Why template language TAL and not Twig? (Benchmark) ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexDesigner Dragonfly v10

Why template language TAL and not Twig? (Benchmark) Reply to topic


Twig is hot at the moment.
It is part of Symphony and therefore CMS like Drupal use it.
However we choose TAL for several reasons.

So i wrapped up a test using themes/default/html/forums/viewtopic_body.xml
This is a more real example then "hello world" as it contains different things like traversal and conditions.

Hardware:
  • Asus P8Z77-V LX
  • Intel i5 3570
  • 8Gb RAM Kingston HyperX KHX1600C9D3P1K2
  • PHP 7.0.4 (Fedora 22, remi repository)

ltime = load php files time
ptime = compile template time

Benchmark without cache:
ltime ptime memory peak TAL 0.00295 0.0115 355640 867232 Twig 0.00363 0.04623 3098440 3198912
Benchmark with cache:
ltime ptime memory peak filesize TAL 0.00288 0.00374 358360 750840 33376 Twig 0.00369 0.00343 705168 439496 80431

When caching is disabled/fails our TAL system is much faster then Twig.
On the other hand, with caching enabled Twig is slightly faster on ptime.
This is also due to the fact that the data put in is a multidimensional array without objects.
With objects (which is default) the outcome might slow down.

Since the differences with cache enabled are low, the real difference comes in use-case.
  1. Which markup do you prefer?
  2. What about invalid html errors?
  3. What about template parse errors?
Although Twig does its best, this is my personal opinion about those questions
  1. I like TAL more
  2. TAL can be used in WYSIWYG editors without problems (the biggest benefit actually)
  3. Our TAL is XML SAX based so it throws an error on incorrect XML, Twig doesn't. Take for example <div style="margin:5px 0;" style="foo>"> code </divv> (notice the error on line 1 and 3)
  4. Our TAL tries to exactly show on which line and column the error occures, Twig is more cryptic

I've attached the used templates so you can compare the template code.
Note: not all TAL is converted to Twig, so this might also be the reason Twig is faster.
Attachment: tal-twig-templates.tar.gz
Description The TAL and Twig templates
Filename tal-twig-templates.tar.gz
Filesize 7.17 KiB
Downloaded 33 Time(s)

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial

Last edited by DJ Maze on Wed Feb 07, 2018 10:03 am; edited 17 times in total


Update: when running the opposite (first twig, then tal) the outcome is that TAL is faster. Odd but nice in our advantage.
ltime ptime memory peak filesize Twig 0.00547 0.00526 731360 849824 80885 TAL 0.0034 0.00454 353832 634296 33376

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial

Last edited by DJ Maze on Mon Apr 11, 2016 10:55 pm; edited 1 time in total


I jus did a compile test for TAL vs Smarty on a website.
Why? Because it uses Smarty and i wanted to know what happens when using TAL.

At compile
- TAL: 122ms, 2.05MiB
- Smarty: 711ms, 2.686MiB

From cache:
- TAL: 74ms, 1.664MiB memory
- Smarty: 74ms, 1.874MiB memory

Compiled files (total of 7):
- TAL: 57,869 B
- Smarty: 81,896 B

When using Smarty it is important to use caching, as you can see that working without it, has a major impact.

It was a cool test to debug the website PHP code, as TAL is more strict and is throwing errors, warnings and notices while Smarty didn't.
This way i was able to fix HTML errors in Smarty templates and fix PHP code errors Smile

I also wrote a Smarty template to TAL converter to make my life easier.
It's not perfect but it did the most conversions which resulted in less html template editing for me.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial

Last edited by DJ Maze on Sun Aug 19, 2018 12:47 pm; edited 6 times in total

All times are UTC


Jump to: