[6.0] [Performance] Access Rules smart preload, reduce memory and time use, for large sites
Pull Request for Issue https://github.com/joomla/joomla-cms/issues/43649.
Summary of Changes
Currently while checking access, the Access::preload() pulling everything from the access table.
It is neglectable for small sites, however for large sites it has huge impact on the site performance.
I added a new method for "smart preload", which allows to preload only needed items. And applied this method for most of the com_content views, where it make sense.
It works as following:
In the View class (or other places before access check) developer call to pre-load access for loaded items with (example for com_content):
$assetsList = ['com_content.article.1', 'com_content.article.2', 'com_content.category.1'];
Access::preloadItems('com_content', $assetsList);
Where the $assetsList is a list for asset name for $items.
This will load access information for these items and its parent in to memory.
And each following call of $user->authorise('core.xxx', $assetName) will reuse preloaded item.
Testing Instructions
Create a site with 20k articles (more is better). Can use following plugin to generate random content https://github.com/Fedik/plg_sampledata_bigdata
Enable debug. Open article detail or blog view. Look for memory usage in the debug bar, and for time.
Actual result BEFORE applying this Pull Request
In my test: memory usage around 45Mb time 200-300ms
Expected result AFTER applying this Pull Request
In my test: memory usage around ~12Mb time ~100ms
Link to documentations
Please select:
- [ ] Documentation link for docs.joomla.org:
- [ ] No documentation changes for docs.joomla.org needed
- [ ] Pull Request link for manual.joomla.org:
- [ ] No documentation changes for manual.joomla.org needed
Will rebase it after upmarge
Is it faster if you add these indexes?
ALTER TABLE `#__assets` ADD INDEX `idx_lft` (`lft`), ADD INDEX `idx_rgt` (`rgt`);
Nope, unfortunately. Before applying the index it took ~250ms, and after ~250ms.
It probably skipping index because of range check:
This pull request has been automatically rebased to 6.0-dev.
@SniperSister please have a look also this one. In combination with https://github.com/joomla/joomla-cms/pull/45542 it should be a bigger improvement in performance for the Content component for large sites.
I updated the PR description, with example how it works.
This pull request has been automatically rebased to 6.1-dev.