Wayfinder
Wayfinder copied to clipboard
Inefficient code slows down Wayfinder
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.
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.
Hi @shamblett. Wayfinder is now managed at https://github.com/modxcms/Wayfinder. Is this something you think you could submit a pull request for?
Its been done by opengeek on this commit, https://github.com/modxcms/Wayfinder/commit/aec5eec3b98ac29aa11c350d82df88fab591dbcc#diff-1bbb67712249e385287340884918ffce