Task #55564
closedImprove GeneralUtility::revExplode performance
100%
Description
GeneralUtility::revExplode
always inverses the string and does multiple array operations, which are quite expensive. To speed it up, it can be split into several parts:
- a regular explode() for "0" parts [i.e. unlimited]
- just the string for 1 part
- manually split for 2 parts (saves the costly array operations)
- the old method for > 2 parts
A quick benchmark showed that 3 only takes half the time of 4 for the case of 2 parts (which currently is the only case in which this method is used in the core).
As this method is used extensively by e.g. GeneralUtility::dirname
, this should give a performance increase of 1-2 ms in the backend.
Updated by Andreas Wolf over 10 years ago
Quick comparison:
- method 1
$explodedValues = explode($delimiter, strrev($string), $count); $explodedValues = array_map('strrev', $explodedValues); $foo = array_reverse($explodedValues);
- method 2
$pos = strrpos($string, $delimiter); $explodedValues = array(substr($string, 0, $pos), substr($string, $pos + 1));
Benchmark with these values:
$delimiter = '/';
$string = '/dir1/dir2/someFile.php';
$count = 2;
Results for 100.000 executions, average over 10 runs:
- method 1: 0.55020709037781
- method 2: 0.24021787643433 (43 % of method 1)
Updated by Gerrit Code Review over 10 years ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27255
Updated by Gerrit Code Review over 10 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27255
Updated by Gerrit Code Review over 10 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27255
Updated by Gerrit Code Review over 10 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27255
Updated by Andreas Wolf over 10 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 7da40c0b10057128c9c5e691cd155c7f255d537e.
Updated by Riccardo De Contardi almost 7 years ago
- Status changed from Resolved to Closed