Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inefficient code slows down Wayfinder #2

Open
shamblett opened this issue Aug 13, 2010 · 3 comments
Open

Inefficient code slows down Wayfinder #2

shamblett opened this issue Aug 13, 2010 · 3 comments

Comments

@shamblett
Copy link

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
Copy link
Author

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.

@jpdevries
Copy link
Collaborator

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

@shamblett
Copy link
Author

Its been done by opengeek on this commit,
modxcms@aec5eec#diff-1bbb67712249e385287340884918ffce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants