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

Config cache for system.xml loader: Speed improvement #1916

Merged
merged 10 commits into from
Jun 9, 2022

Conversation

lamskoy
Copy link
Contributor

@lamskoy lamskoy commented Dec 21, 2021

Description (*)

System.xml loading is not cached anywhere. So each time you open backend page in Magento it scans ALL system.xml inside all modules, merges them and doesn't cache this big XML structure.

Header menu is rendered from system.xml contents too, not only config fields and sections!

My PR implements caching of this stuff.

It decreases any admin page load time in about 1.5 sec on second load on my local machine :)

Manual testing scenarios (*)

Open any magento config page twice and measure time of page load

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@github-actions github-actions bot added the Component: Adminhtml Relates to Mage_Adminhtml label Dec 21, 2021
@luigifab
Copy link
Collaborator

luigifab commented Dec 22, 2021

For me:

  • before / after
  • From 550/650 ms to 350/450 ms at localhost with PHP 7.4 when only CONFIG cache is enabled.
  • From ~1700 ms to 1350/1450 ms at localhost with PHP 7.4 when all cache are disabled.

@luigifab
Copy link
Collaborator

I think that this error is due to this PR (exception.log):

Exception: "$string" parameter for simplexml_load_string is not a string in
  lib/Varien/Simplexml/Config.php:517

@Flyingmana
Copy link
Member

From ~1700 ms to 1350/1450 ms at localhost with PHP 7.4 when all cache are disabled.

sounds like there is still a check missing, to not cache it when the cache is disabled?

@elidrissidev
Copy link
Member

elidrissidev commented Dec 23, 2021

Agree with @Flyingmana, I don't see any code that checks if the cache is enabled. Example from Mage_Api_Model_Config:

if (Mage::app()->useCache('config_api')) {
if ($this->loadCache()) {
return $this;
}
}
$config = Mage::getConfig()->loadModulesConfiguration('api.xml');
$this->setXml($config->getNode('api'));
if (Mage::app()->useCache('config_api')) {
$this->saveCache();
}
return $this;

@lamskoy
Copy link
Contributor Author

lamskoy commented Dec 31, 2021

Agree with @Flyingmana, I don't see any code that checks if the cache is enabled. Example from Mage_Api_Model_Config:

if (Mage::app()->useCache('config_api')) {
if ($this->loadCache()) {
return $this;
}
}
$config = Mage::getConfig()->loadModulesConfiguration('api.xml');
$this->setXml($config->getNode('api'));
if (Mage::app()->useCache('config_api')) {
$this->saveCache();
}
return $this;

Yeah, you're right. Pushed new commit with fix. Bound to 'config' cache

@elidrissidev
Copy link
Member

Since you're including it with the CONFIG tag, can you also update the description to include system.xml? Something like:

-System(config.xml, local.xml) and modules configuration files(config.xml).
+System(config.xml, local.xml) and modules configuration files(config.xml, system.xml).

Screen Shot 2021-12-31 at 12 59 57 PM

@lamskoy
Copy link
Contributor Author

lamskoy commented Jan 4, 2022

Done with description
"System(config.xml, local.xml) and modules configuration files(config.xml, system.xml)"

@github-actions github-actions bot added the Component: Core Relates to Mage_Core label Jan 4, 2022
@luigifab
Copy link
Collaborator

luigifab commented Jan 28, 2022

I still get the following error (I didn't searched why - PHP 8.0): Exception: "$string" parameter for simplexml_load_string is not a string in lib/Varien/Simplexml/Config.php:517
After clearing cache and after refresh any configuration pages.

@tmotyl
Copy link
Contributor

tmotyl commented Jan 28, 2022

I think this chnage deservces an comment in readme/changelog, as it changes an expected behaviour developers have -> now they will need to clear the cache after changing system.xml

app/code/core/Mage/Adminhtml/Model/Config.php Outdated Show resolved Hide resolved
@github-actions github-actions bot added the translations Relates to app/locale label May 25, 2022
luigifab
luigifab previously approved these changes May 25, 2022
@luigifab luigifab added the performance Performance related label May 25, 2022
@luigifab luigifab mentioned this pull request May 25, 2022
4 tasks
@fballiano
Copy link
Contributor

is phpstan right about this?

Schermata 2022-06-07 alle 17 03 35

@elidrissidev
Copy link
Member

Yes, because that parameter is not passed to the parent class.

fballiano
fballiano previously approved these changes Jun 8, 2022
Copy link
Member

@elidrissidev elidrissidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two more changes to please phpstan

app/code/core/Mage/Adminhtml/Model/Config.php Outdated Show resolved Hide resolved
app/code/core/Mage/Adminhtml/Model/Config.php Outdated Show resolved Hide resolved
@elidrissidev
Copy link
Member

@fballiano What do you think about mentioning this change in README under "Between Magento 1.9.4.5 and OpenMage 19.x" as tmotyl suggested?

fballiano
fballiano previously approved these changes Jun 8, 2022
@fballiano
Copy link
Contributor

@elidrissidev added info to README ;-)

Copy link
Member

@elidrissidev elidrissidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested once again and everything works well for me, and also a big improvement in loading speed across the Admin area!

@fballiano fballiano merged commit 14cf6fa into OpenMage:1.9.4.x Jun 9, 2022
@github-actions
Copy link

github-actions bot commented Jun 9, 2022

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
7 runs  ±0  5 ✔️ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit 14cf6fa. ± Comparison against base commit 417a20d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Adminhtml Relates to Mage_Adminhtml Component: Core Relates to Mage_Core documentation performance Performance related translations Relates to app/locale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants