Wayfinder icon indicating copy to clipboard operation
Wayfinder copied to clipboard

Inefficient code slows down Wayfinder

Open shamblett opened this issue 14 years ago • 3 comments

Lines 617 and 618 of the main wayfinder class(wayfinder.class.php) are inefficently getting a chunk twice, from my cachegrind outputs this can seriously affect Wayfinders performance, the lines :-

if ($this->modx->getChunk($tpl) != "") { $template = $this->modx->getChunk($tpl);

can be easily optimised to get the chunk once, then test it, not twice as above.

shamblett avatar Aug 13 '10 08:08 shamblett

This is actually worse than you think, besides the above you don't want to use getChunk here as this calls the parser for every supplied chunk template, you just want to use a getObject for the chunk name and let Wayfinder handle the parsing.

Changing the code to this :-

if ($tpl == '') return false; $template = ""; $templateObject = $this->modx->getObject('modChunk', array('name'=>$tpl)); $template = $templateObject->get('snippet'); if ($template != "") { return $template;

reduces the cumulative page load time from cachegrind outputs from 2770ms to 1941ms, calls to the function processElementTags drop from 651 to 331, so we have a 30% better page load time. Timings from my local dev test site.

shamblett avatar Sep 20 '10 13:09 shamblett

Hi @shamblett. Wayfinder is now managed at https://github.com/modxcms/Wayfinder. Is this something you think you could submit a pull request for?

jpdevries avatar Oct 20 '13 22:10 jpdevries

Its been done by opengeek on this commit, https://github.com/modxcms/Wayfinder/commit/aec5eec3b98ac29aa11c350d82df88fab591dbcc#diff-1bbb67712249e385287340884918ffce

shamblett avatar Nov 07 '13 11:11 shamblett