Ok,
We have built a site for a client who wanted a number 'widgets' (twitter feed, related pages box, page author, etc) to show in the right hand column. They wanted the flexibility to pick and chose these depending on the page rather than have them pre defined by the template.
We set this up using a number of check box TV's (for the sake of argument I will call these [[*show-chunk]]) with yes and no options. Yes=1 and No=0 which is the default.
There is then a chunk like this to process this tv value and return the 'widget':
[[*show-chunk:equals=`1`:then=`[[$chunk]]`:else=``]]
When a number of these are used together it seems to have a huge impact on page load times. By this I mean the actual PHP processing time of the page.
By removing parts of the template and chunks we had worked out [[*show-chunk:equals=`1`]] disproportionately to the load time of the page.
With one of these calls: <!--MySQL: 0.0267 s, 3 request(s), PHP: 4.7374 s, total: 4.7641 s, document retrieved from database. -->
Without it: <!--MySQL: 0.0132 s, 2 request(s), PHP: 3.2442 s, total: 3.2574 s, document retrieved from database. -->
On its own not a major issue but when this is combined with 6 other identical calls these push page loads over 10 seconds before caching. Which is not acceptable!
Has anyone have similar issues?
OR
Would a snippet do this faster for multiple yes/no tv's?
This is in Modx 2.2.6pl (traditional). I can post the whole stack of template, chunks and snippets but this might just be distracting. It took us about 3 hours of trying different combinations to trace back the performance hit to this.
Ok so really the issue must be that $chunk gets parsed weither *show-chunk:equals=`1` or not.
Cumulatively this might account for the hit to page load speeds.
Your improvement saves about 0.5 seconds per optional chunk.
Is there a away to only parse the $chunk if *show-chunk:equals=`1` and not parse otherwise? Or is that just how output filters work?
See how a snippet compares:
<?php
/* ShowChunk snippet */
if ($modx->resource->getTVValue('show-chunk')) {
return $modx->getChunk('ChunkName');
}
If speed is really an issue, repurposing an unused resource field should be faster yet. Say you're not using the description field for anything, you could put a 1 or a 0 in that field and do this:
<?php
/* ShowChunk snippet */
if ($modx->resource->get('introtext')) {
return $modx->getChunk('ChunkName');
}
You could even keep the TV and write the introtext (or whatever) field from it in a plugin connected to OnDocFormSave. The TV would be ignored during page loads. It would just be there for user convenience. If you did that, you could use the deprecated 'donthit' field (assuming that it still exists), which is a boolean field. It can't be set in the Create/Edit Resource form, but the plugin would set it for you.
Slightly off topic but is this still an impact on performance:
[[*TV:notemtpy=`[[$chunk]]`]] ?
I have multiple such calls, could they impact performance?
Quote from: nickyz at Mar 07, 2013, 08:15 AMSlightly off topic but is this still an impact on performance:
[[*TV:notemtpy=`[[$chunk]]`]] ?
I have multiple such calls, could they impact performance?
it's better to do:
[[*TV:default=`[[$chunk]]`]]
[ed. note: eighthday last edited this post 13 years, 6 months ago.]