template engine thoughts

Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here.
Forum rules
Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here. Feature requests are closed.
User avatar
bassul
Posts: 11
Joined: Sun Jun 25, 2006 12:39 am
Contact:

template engine thoughts

Post by bassul »

First of all, congratulations for the work you're doing.
Story: I'm currently being a hobby administrator for a not-so-large 2.0.X forum, and some of the guys are always arguing towards switching to a commercial forum. While I like the idea of sticking to open source, I did some reseach concerning the Olympus features.

Concerning the template engine, and being that I understand things as a programmer, this topic has drawn my attention:
Styling->Smarty.
I made a small script in order to see if the subSilver theme can be translated into a smarty-style subSilver theme and then I benchmarked the faq page by using a small test script that is bypassing the normal workflow of the forum (database queries and such), aiming to just compare speed for the two template solutions.

I'd like to share the results, give feedback and make some suggestions, but I understand this is not the right place to do it. Styling would not be right place either, as I wouldn't like getting into arguments about style syntax. Please point me in the right direction, as there isn't any tracker I could find on the sourceforge project page.
http://sourceforge.net/tracker/?group_id=7885" target="_blank
No Accessible Trackers Found
Cheers,
Tudor

User avatar
dhn
Registered User
Posts: 1518
Joined: Wed Jul 04, 2001 8:10 am
Location: Around the corner
Contact:

Re: template engine thoughts

Post by dhn »

Before you start spending even more time on this. The compiled templates are cached, so the actual generation of templates does only happen when either the cache is empty or templates are changed (and the admin has "Recompile stale templates" enabled). This will hardly happen in an active forum, so template compilation time is negligible.

User avatar
bassul
Posts: 11
Joined: Sun Jun 25, 2006 12:39 am
Contact:

Re: template engine thoughts

Post by bassul »

template compilation time is negligible.
True, and I expected that from the start. That is even one of the points, that performance is quite similar.
Cheers,
Tudor

User avatar
dhn
Registered User
Posts: 1518
Joined: Wed Jul 04, 2001 8:10 am
Location: Around the corner
Contact:

Re: template engine thoughts

Post by dhn »

Well, feel free to post and discuss your results here, the rewritten template system is a new feature after all. ;)

User avatar
bassul
Posts: 11
Joined: Sun Jun 25, 2006 12:39 am
Contact:

Re: template engine thoughts

Post by bassul »

Converter scripts:
general script - template_convert.sh and filter-script: template_smarty.pl. (place them in the same directory, make them executable and then execute template_convert.sh with $1=the directory path for the subSilver template $2=directory path for the new template, eg

Code: Select all

./template_convert.sh subSilver new
if run from the styles directory).

Test files used:
smarty_faq.php and bb3_faq.php (Smarty files are placed in the root of the phpBB installation, template used is styles/new).

Results for 10000 requests ( command used ):

Code: Select all

ab2 -k -c 10 -n 10000 http://localhost/%url%
  • apache-2.0.54, mod_php-5.1.4:
    • bb3_faq.php: 248.85 seconds
    • smarty_faq.php: 277.30 seconds
  • apache-2.0.54, mod_php-5.1.4, eaccelerator-0.9.5-beta2
    • bb3_faq.php: 97.80 seconds
    • smarty_faq.php: 96.19 seconds
Some observations:
  • As noted previously, template compilation time is constant, after compiling both solutions simply include the compiled templates.
  • Speed is only marginally influenced by length of text in the output, or memory allocation as a result of different styles in assigning the values to the template data array.
  • The compiled files produced by each system are pretty similar in the end, the difference being mainly in the loop compilation (foreach in the case of the converted template versus plain for for phpBB3 template loops). I thought at first that the foreach $ary as $var syntax produced by Smarty might be the cause of the penalty, but using foreach $ary as &$var produced similar results.
Conclusions
These results have shown to me that the difference in performance between the two solution in non-eaccelerated mode was caused mainly by the size of the php source files: ~14K for phpBB3's template.php and ~62K for Smarty.class.php. Template compilation code size doesn't really matter as it's only loaded at first. So yes, the argument of "bloated code" is won by phpBB3.

The important result is, however, that the mode of operation and the results produced by both engines are very similar. The template syntax doesn't really matter, since one can convert easily a phpBB-style template to smarty syntax.

And now the personal view:
I know there will be currently no change in the Olympus concerning the template implementation, but my hopes are that I could present some clear arguments towards considering using (in the future) a stripped Smarty implementation for template compilation, rather than using some of Smarty code into an own implementation.

It all depends on where you want to go in the end, if OS community as a whole is party of your plans. I will try to highlight the advantages of both approaches in the long run, but my main idea is that both projects could benefit from the developments, rather than evolving on parallel paths, in the same way as GTK+ has chosen Cairo, Mozilla has chosen to separate the engine from the browser, and so on.
Advantages of phpBB 3.x custom template solution:
  • smaller code size
  • implementation adapted to personal needs
    Disadvantages:
    • 'fresh'-er code (that usually means more risk for instability and exploitability)
    • code creation and maintainance takes time that could be used for something else
Advantages of using Smarty for template backend:
  • can be done with virtually no change in syntax (Smarty can use custom delimiters and tags + one can easily convert to smarty syntax)
  • long way of improvements of bug fixes (current 2.6 branch started in 2003), read stability and security
  • more features, some designers are used to
    Disadvantages:
    • Bigger code size, however marginal when an optimizer is used.
    • some hate the syntax, as I have shown this can be changed quite easily
Cheers,
Tudor

code reader
Registered User
Posts: 653
Joined: Wed Sep 21, 2005 3:01 pm

Re: template engine thoughts

Post by code reader »

i will take the risk (i have been banned in the past for similar comments):

imo, using smarty (or, for that matter, any open-source well established template engine) has a huge advantage over "homegrown", because it taps the brains of a whole "new" group of people who put much more time and thought into the narrow area of template engine, in contrast with getting a fraction of the cpu cycles of phpbb development team.
even if smarty is no better than the homegrown, you would gain from much more extensive testin which spells improved stability, future development, from design tools people have built and will build for it, and by helping to establish a standard, and potentially gaining from it.

the main reason NOT to use smarty, and the reason i think it will not be used is NIH mentality.

Yawnster
Registered User
Posts: 342
Joined: Sat Jan 29, 2005 9:18 pm
Location: London, UK
Contact:

Re: template engine thoughts

Post by Yawnster »

Ok code reader.. so a project like phpBB accepts and uses Smarty.. a security hole developers in the code maintained by the 3rd party.. who get the blame?? Who gets the bad press?? I will let you answer..

I think that the NIH policy is actually why phpBB has become so popular, it makes sure the developers know exactly what is going on throughout the entire code and not just using an API to get certain features..

I think that 3rd code has its place, but in a forum or anything web-based I feel that that is not it. It will purely add bloat to a package that is designed to be portable and reusable.. I mean if you have Smarty installed with phpBB, 2 packages.. 2 sets of updates.. (admittedly if this happens the updates will obviously be merged) but some will want to update separately..

I think that although your reasoning is indeed correct, it would speed up development and yes it would tap into a new series of minds, I feel the cons severely outweigh the pros on this particular discussion.

Yawnster

SamG
Registered User
Posts: 1241
Joined: Fri Aug 31, 2001 6:35 pm

Re: template engine thoughts

Post by SamG »

I'm not clear on the real world benefits here. If the phpBB developers have to (re)learn and strip down/personalize Smarty repeatedly to take advantage of the focused development behind Smarty, what are the clear, unarguable benefits of using Smarty in the first place?

code reader
Registered User
Posts: 653
Joined: Wed Sep 21, 2005 3:01 pm

Re: template engine thoughts

Post by code reader »

Yawnster wrote: Ok code reader.. so a project like phpBB accepts and uses Smarty.. a security hole developers in the code maintained by the 3rd party.. who get the blame?? Who gets the bad press?? I will let you answer..
imo, "blame" and "bad press" are just diversions.
high quality and stability are the real issues.
this is exactly the open source spirit: not "who's fault is it", but rather "how can it be better".
when every project, large and small, invent the wheel over and over again, there may be some fun, but usually the end results are not as good.
it would (maybe) make sense if phpbb template engine contained some amazing innovation not present in other template engines. ttbomk, this is not the case.
the open source spirit is that of co-opting code and cooperation among projects. when a bug in the template engine is discovered elsewhere, any project that uses it profits from the bug-fix.
there is no doubt in my mind that smarty is cleaner that the template engine currently in use in phpbb: it had been out there for several years now, it is incorporated in hundreds (if not thousands) of products/projects, and went though extensive testing. phpbb template engine have just now hatched out of its egg.
SamG wrote: I'm not clear on the real world benefits here. If the phpBB developers have to (re)learn and strip down/personalize Smarty repeatedly to take advantage of the focused development behind Smarty, what are the clear, unarguable benefits of using Smarty in the first place?
i agree that "If the phpBB developers have to (re)learn and strip down/personalize Smarty repeatedly", the advantage is not huge.
otoh, smarty is designed and built not as a stand alone product/projust, but as an engine to be incorporated into products/projects.
as such, it would be natural and easy to take it as is, without a singel change, and incorporate it into phpbb.



look, guys/gals, i am not a smarty salesperson. my point is that, imo, phpbb would gain by incorporating, where appropriate, some well-designed and well-built open-source projects. unlike Yawnster, i think that phpbb success is in spite of its NIH mentality, and not because of it.

just my 2c. i really do not plan to participate in any holy war about NIH, smarty, or anything else.
:) :) :) :) :) :) :)

SamG
Registered User
Posts: 1241
Joined: Fri Aug 31, 2001 6:35 pm

Re: template engine thoughts

Post by SamG »

code reader wrote: i agree that "If the phpBB developers have to (re)learn and strip down/personalize Smarty repeatedly", the advantage is not huge.
otoh, smarty is designed and built not as a stand alone product/projust, but as an engine to be incorporated into products/projects.
as such, it would be natural and easy to take it as is, without a singel change, and incorporate it into phpbb.
bassul suggested a stripped and possibly revised syntax Smarty engine, so I took it that we weren't discussing dropping Smarty into phpBB as is.

Just as a side note, phpBB's template engine really isn't "just now hatched out of its egg." The first true phpBB template engine was released with phpBB 2.0.0. Since many people enjoy pointing out how long ago that was, it's not entirely unfair of me to observe that the developers have no little experience with phpBB's approach to templating.
Last edited by SamG on Mon Jun 26, 2006 9:13 pm, edited 2 times in total.

Post Reply