Skip to content

Commit 0419441

Browse files
authored
Improve performance of getData retrieval
The getData() method is called hundred of thousand of times on PLP's without block_cache. Even when everything is cached without FPC, this method can be called thousands of times. A more direct retrieval of data and avoiding extra function calls benefits performance quite a bit. The following performance gains are monitored from a local environment in production mode: Former setup PLP without block_html: TIMER: 448.403317 ms COUNT AMOUNT: 284881x New setup PLP without block_html: TIMER: 251.413533 ms COUNT AMOUNT: 284881x Former setup PLP with block_html TIMER: 31.084917 ms COUNT AMOUNT: 16310x New setup PLP with block_html: TIMER: 13.384665 ms COUNT AMOUNT: 16310x
1 parent 49bd706 commit 0419441

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/internal/Magento/Framework/DataObject.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@ public function getData($key = '', $index = null)
128128
return $this->_data;
129129
}
130130

131-
/* process a/b/c key as ['a']['b']['c'] */
132-
if ($key !== null && strpos($key, '/') !== false) {
131+
$data = $this->_data[$key] ?? null;
132+
if ($data === null && $key !== null && strpos($key, '/') !== false) {
133+
/* process a/b/c key as ['a']['b']['c'] */
133134
$data = $this->getDataByPath($key);
134-
} else {
135-
$data = $this->_getData($key);
136135
}
137136

138137
if ($index !== null) {

0 commit comments

Comments
 (0)