Skip to content

Commit 69444df

Browse files
Magento Framework - Performance improvements
- cache parents list in Code/Reader/ClassReader.php - replace array_key_exists() by isset() (2nd a bit faster, but that will change in PHP 7.4)
1 parent db0dce6 commit 69444df

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/internal/Magento/Framework/Code/Reader/ClassReader.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class ClassReader implements ClassReaderInterface
99
{
10+
private $parentsCache = [];
11+
1012
/**
1113
* Read class constructor signature
1214
*
@@ -54,6 +56,10 @@ public function getConstructor($className)
5456
*/
5557
public function getParents($className)
5658
{
59+
if (isset($this->parentsCache[$className])) {
60+
return $this->parentsCache[$className];
61+
}
62+
5763
$parentClass = get_parent_class($className);
5864
if ($parentClass) {
5965
$result = [];
@@ -75,6 +81,9 @@ public function getParents($className)
7581
$result = [];
7682
}
7783
}
84+
85+
$this->parentsCache[$className] = $result;
86+
7887
return $result;
7988
}
8089
}

lib/internal/Magento/Framework/Interception/PluginList/PluginList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function __construct(
138138
protected function _inheritPlugins($type)
139139
{
140140
$type = ltrim($type, '\\');
141-
if (!array_key_exists($type, $this->_inherited)) {
141+
if (!isset($this->_inherited[$type])) {
142142
$realType = $this->_omConfig->getOriginalInstanceType($type);
143143

144144
if ($realType !== $type) {

lib/internal/Magento/Framework/ObjectManager/Definition/Runtime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(\Magento\Framework\Code\Reader\ClassReaderInterface
4545
*/
4646
public function getParameters($className)
4747
{
48-
if (!array_key_exists($className, $this->_definitions)) {
48+
if (!isset($this->_definitions[$className])) {
4949
$this->_definitions[$className] = $this->_reader->getConstructor($className);
5050
}
5151
return $this->_definitions[$className];

0 commit comments

Comments
 (0)