Task #55198

Epic #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

Added by Jo Hasenau over 5 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Must have
Assignee:
Category:
Performance
Target version:
Start date:
2014-01-21
Due date:
% Done:

100%

TYPO3 Version:
6.2
PHP Version:
5.3
Tags:
Complexity:
Sprint Focus:

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:

  1. It must not be replaced when there is a limit in the original method call
  2. It must not be replaced when there is no foreach loop making use of the array immediately after the method call
  3. It must be replaced by at least a trim within the following loop
  4. 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

Associated revisions

Revision 0d383257 (diff)
Added by Michiel Roos over 5 years ago

[TASK] Optimize GeneralUtility::trimExplode()

This often used method can be about 5% more performant by rewriting it.

Change-Id: Iee80a35ebd98c3521a75977bc7ab45d170858e24
Resolves: #55198
Releases: 6.2
Reviewed-on: https://review.typo3.org/27086
Reviewed-by: Markus Klein
Tested-by: Markus Klein

History

#1 Updated by Michiel Roos over 5 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.

#2 Updated by Ernesto Baschny over 5 years ago

  • Parent task set to #55078

#3 Updated by Gerrit Code Review over 5 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

#4 Updated by Gerrit Code Review over 5 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

#5 Updated by Gerrit Code Review over 5 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

#6 Updated by Gerrit Code Review over 5 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

#7 Updated by Gerrit Code Review over 5 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

#8 Updated by Gerrit Code Review over 5 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

#9 Updated by Gerrit Code Review over 5 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

#10 Updated by Gerrit Code Review over 5 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

#11 Updated by Gerrit Code Review over 5 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

#12 Updated by Gerrit Code Review over 5 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

#13 Updated by Gerrit Code Review over 5 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

#14 Updated by Gerrit Code Review over 5 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

#15 Updated by Gerrit Code Review over 5 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

#16 Updated by Gerrit Code Review over 5 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

#17 Updated by Gerrit Code Review over 5 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

#18 Updated by Gerrit Code Review over 5 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

#19 Updated by Gerrit Code Review over 5 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

#20 Updated by Gerrit Code Review over 5 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

#21 Updated by Markus Klein over 5 years ago

The title "Replace trimExplode + foreach with explode + trim within foreach" is not correct anymore, the patch does much less.

#22 Updated by Gerrit Code Review over 5 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

#23 Updated by Michiel Roos over 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#24 Updated by Riccardo De Contardi almost 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF