Task #55198
closedEpic #55070: Workpackages
Epic #55065: WP: Overall System Performance (Backend and Frontend)
Story #55078: Optimize PHP code performance in TYPO3 methods
Replace trimExplode + foreach with explode + trim within foreach
100%
Description
There are lots of methods making use of the costly trimExplode method using a foreach loop on the exploded array immediately after the method call.
The result is an array_map plus at least one (sometimes a second) foreach loop over the array of exploded items, one (or two) inside the trimExplode and one outside over the resulting array. Performancewise foreach is not just faster in most of the cases but has a much smaller memory footprint, so it would be a good idea to just stay with trimExplode when this is useful and necessary.
Since most of the cases don't make use of the limit parameter of trimExplode, we should replace any call to that method based on the following rules:
- It must not be replaced when there is a limit in the original method call
- It must not be replaced when there is no foreach loop making use of the array immediately after the method call
- It must be replaced by at least a trim within the following loop
- It must be replaced by a trim AND a check for empty values within the following loop, when the third parameter was set to TRUE before
Updated by Michiel Roos about 11 years ago
Here are some benchmarks http://pastebin.com/SZjWDDk9
preg_split is quite fast for 'most' cases.
We should indeed inspect all calls and see we actually need to trim the values.
The following methods do not handle whitespace:- \TYPO3\CMS\Core\Utility\GeneralUtility::inList()
- \TYPO3\CMS\Core\Utility\GeneralUtility::rmFromList()
- \TYPO3\CMS\Core\Utility\GeneralUtility::expandList()
Code using these methods should not be calling trimExplode, but just plain explode.
I have not done any inspection yet.
Updated by Gerrit Code Review about 11 years ago
- Status changed from New 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/27086
Updated by Gerrit Code Review about 11 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/27086
Updated by Gerrit Code Review about 11 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/27086
Updated by Gerrit Code Review about 11 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/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 13 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 14 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 15 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 16 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review about 11 years ago
Patch set 17 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Gerrit Code Review almost 11 years ago
Patch set 18 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Markus Klein almost 11 years ago
The title "Replace trimExplode + foreach with explode + trim within foreach" is not correct anymore, the patch does much less.
Updated by Gerrit Code Review almost 11 years ago
Patch set 19 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27086
Updated by Michiel Roos almost 11 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 0d383257ba1a510da01b99f6408193b925d0fbaa.
Updated by Riccardo De Contardi over 7 years ago
- Status changed from Resolved to Closed