-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
generate URLs faster #88
base: master
Are you sure you want to change the base?
Conversation
Also note this is a heavy site with tons of extensions and modules - I would expect the page load improvement to be more pronounced on a lighter site. |
Ah, our old friend the static array. Good to see you again. |
Awesome Jon, we're going to test this on a few sites |
} | ||
else { | ||
return $longest; | ||
self::$knownPaths[$newPath] = TRUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sets this here, but then never uses it again except to check if it's set, and then down below ALWAYS returns $path. Is it missing a return $newPath
here? And if so, shouldn't it cache the new path and return that if cached?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh - hmm, yes. I need to revise this. I did my initial tests against pages that didn't have params (i.e. the route matched civicrm_menu
exactly). Then I modified it to support params but didn't go back and revise this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also...when did this get to be 5 levels of nested if
s? Yeesh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - I fixed this and reduced the nested if
s to a max of 3, but I haven't tested the new patch yet. I was actually hoping some CI existed on this repo that would run tests, but oh well. I'll look at this later today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 levels of nested ifs
That's how you know it's civi. No copyright block needed in the file.
hoping some CI existed on this repo
There isn't anything automatic, but what prompted me to take a closer look at the code was that as a sanity check I ran it with civicarrot against the cdntaxreceipts extension's tests. You managed to crash github so that there aren't even logs of the phpunit part, which is no easy task: https://github.com/SemperIT/CiviCARROT/actions/runs/6476564520/job/17585470546. It's running again now: https://github.com/SemperIT/CiviCARROT/actions/runs/6485761313/job/17612539157
civicrm_entity and webform's tests also run in a drupal 8 environment, but I don't think they hit too many civi urls, usually just on the drupal side, so for this PR might not pick anything up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It crashed again but not as bad. Normally the run takes about 15 min so I'm guessing it's getting into some loop. Just clicking around manually I don't see anything obvious. I'll try to see what the test issue is about (the config file warning isn't relevant).
90fcbf0
to
8c1a2cf
Compare
} | ||
$routesInitialized = \CRM_Core_DAO::singleValueQuery('SELECT COUNT(*) from civicrm_menu'); | ||
if (!$routesInitialized) { | ||
\CRM_Core_Menu::store(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test issue is that during an initial install of civi, this line generates an infinite loop, because there is nothing in civicrm_menu, and then calling store() ends up back here again recursively while trying to build menu links.
That might also happen during a cache clear - I didn't test that.
I did test menu rebuild / rebuild triggers with this patch, and it causes an "out of memory" php error. |
8c1a2cf
to
20a1473
Compare
OK, I pushed a fix for the infinite loop issue. I doubt the cdntaxreceipts extension calls |
Ok it's running now (https://github.com/SemperIT/CiviCARROT/actions/runs/6502732003/job/17662200722) but just noting that I'm not sure the CRM_Core_Menu::get() call lower down will ever return anything now? Since nothing will ever get put into civicrm_menu. I think it would now go like:
|
It passed and it's MUCH faster, but I'd want to check out my theory above because if it's true then the whole function could just be replaced with |
|
I tried returning just |
Right. But to be extra cautious, one could say: - if (isset(self::$knownPaths[$path])) {
- return self::$knownPaths[$path];
- }
+ if (class_exists('Civi', FALSE) && isset(Civi::$statics[__CLASS__]['knownPaths'][$path])) {
+ return Civi::$statics[__CLASS__]['knownPaths'][$path];
+ } Even if |
Ah that seems like a quick win on the static, so with that updated I'd be good to give a merge-ready pending some sanity runs and any thoughts from @jackrabbithanna. |
Tested again, and now no problems on cache clears and menu / trigger rebuilds. We've put this patch on a site we are actively developing on to put it through its paces |
We've put this on a couple of sites, and found an issue. Not every path is in Reading through the code, I'm not sure why this matters, since we're calling |
I decided to see if I could get this function to just If the route is already in the I'm trying to see if we can a) remove all the routes but |
This follows on a conversation from January with @jackrabbithanna toward addressing the performance of CiviCRM page loads.
We currently call
CRM_Core_Menu::items()
each timeCRM_Core_System::url()
is called.url()
is called many times per page - andCRM_Core_Menu::items()
is a full rebuild ofcivicrm_menu
- scanning for and loading XML files, Afforms, anything that can add a route.This patch cuts an average of 10-12% off every page load time - except search results, which were comparable (I'm not sure why). It also doesn't change load time for SearchKit AJAX requests - presumably because URLs are generated in JS, not PHP.