joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[6.0] [Performance] Access Rules smart preload, reduce memory and time use, for large sites

Open Fedik opened this issue 1 year ago • 5 comments

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

Fedik avatar Sep 14 '24 10:09 Fedik

Will rebase it after upmarge

Fedik avatar Sep 14 '24 10:09 Fedik

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: Screenshot 2024-09-14_14-09-28

Fedik avatar Sep 14 '24 11:09 Fedik

This pull request has been automatically rebased to 6.0-dev.

HLeithner avatar Mar 04 '25 17:03 HLeithner

@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.

Fedik avatar Jun 07 '25 09:06 Fedik

I updated the PR description, with example how it works.

Fedik avatar Jun 10 '25 09:06 Fedik

This pull request has been automatically rebased to 6.1-dev.

HLeithner avatar Aug 31 '25 11:08 HLeithner