0

I'm looking for MODX getChunk() alternative mostly because it seems to be really slow when outputting a lot of times. When I use it once in a snippet then I could hardly notice its speed, but if it's used in a loop then each second matters.

I'm outputting ~1300 images 100 per page as part of the gallery and it takes:

  • 6-7 seconds when the output is placed in a chunk $output .= $modx->getChunk('chunkname');
  • 2-3 seconds when the output is plain HTML

Does anyone know faster alternative to output the result of image query using chunk?

jacek_podwysocki
  • 807
  • 10
  • 30

2 Answers2

0

What does your chunk look like?

You might consider abandoning the getChunk() call and just inlining your html:

$output = '';
foreach ($images as $img) {
    $output .= '<li><a href="'.$img['path'].'" alt="'.$img['name'].'" /></li>';
}

return $output;

Yeah yeah, it's bad practise but when faced with the alternative taking more than twice as long it's not a bad optimisation.

okyanet
  • 3,106
  • 1
  • 22
  • 16
  • I'm also wondering which Revo version you are using. I think from 2.2+ some optimisations were made to getChunk, significantly speeding it up. – okyanet Oct 15 '12 at 00:08
  • I'm using 2.2.4 but still the use of getChunk seems to double the time needed to output images. I didn't see the problem before but when query 1330 images and output 100 in a pagination then the timing is quite bad. Anything over 3 seconds for 100 images is too much... – jacek_podwysocki Oct 15 '12 at 00:14
  • I could use the inline html but that's not the elegant way and I'm wondering what sense makes the dynamic retrieval of chunk if its processing takes that much time – jacek_podwysocki Oct 15 '12 at 00:15
  • 1
    Check out this thread on the modx forums, some useful stuff in there that might help: http://forums.modx.com/thread/?thread=74071&page=3 – okyanet Oct 15 '12 at 12:36
  • The problem with the above mentioned method is that if I declare a chunk "$chunkie = $modx->getObject('modChunk', array('name' => 'thumbTemplate'));", then do the foreach loop where I process the chunk "$output .= $chunkie->process($itemArray);" the output keeps outputting the same plcaholders value called from the chunk...This didn't work "$chunkie->_processed = false;" – jacek_podwysocki Oct 15 '12 at 12:44
0

There's another solution from more of an architectural level - 1300 images is a huge amount to load on one page!

Depending on your design, why not load the first 20 - 30 and implement some kind of infinite scrolling, loading in the rest by ajax (in lots of 20 or so) when the user begins to scroll.

That's going to take the load off your server, save bandwidth, provide a faster user experience. And get around the slow getChunk call.

okyanet
  • 3,106
  • 1
  • 22
  • 16