Project

General

Profile

Actions

Task #55198

closed

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 10 years ago. Updated over 6 years ago.

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

100%

Estimated time:
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
Actions #1

Updated by Michiel Roos about 10 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.

Actions #2

Updated by Ernesto Baschny about 10 years ago

  • Parent task set to #55078
Actions #3

Updated by Gerrit Code Review about 10 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

Actions #4

Updated by Gerrit Code Review about 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/27086

Actions #5

Updated by Gerrit Code Review about 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/27086

Actions #6

Updated by Gerrit Code Review about 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/27086

Actions #7

Updated by Gerrit Code Review about 10 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

Actions #8

Updated by Gerrit Code Review about 10 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

Actions #9

Updated by Gerrit Code Review about 10 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

Actions #10

Updated by Gerrit Code Review about 10 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

Actions #11

Updated by Gerrit Code Review about 10 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

Actions #12

Updated by Gerrit Code Review about 10 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

Actions #13

Updated by Gerrit Code Review about 10 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

Actions #14

Updated by Gerrit Code Review about 10 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

Actions #15

Updated by Gerrit Code Review about 10 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

Actions #16

Updated by Gerrit Code Review about 10 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

Actions #17

Updated by Gerrit Code Review about 10 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

Actions #18

Updated by Gerrit Code Review about 10 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

Actions #19

Updated by Gerrit Code Review about 10 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

Actions #20

Updated by Gerrit Code Review about 10 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

Actions #21

Updated by Markus Klein about 10 years ago

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

Actions #22

Updated by Gerrit Code Review about 10 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

Actions #23

Updated by Michiel Roos about 10 years ago

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

Updated by Riccardo De Contardi over 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF