Task #54525

Epic #55070: Workpackages

Epic #55065: WP: Overall System Performance (Backend and Frontend)

Story #55078: Optimize PHP code performance in TYPO3 methods

Optimize file- and path functions in GeneralUtility

Added by Michiel Roos almost 6 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Performance
Target version:
Start date:
2013-12-20
Due date:
% Done:

100%

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

Description

Optimize several frequently called methods:
  • getFileAbsFileName()
  • validPathStr()
  • isAllowedAbsPath()
  • verifyFilenameAgainstDenyPattern()

Associated revisions

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

[TASK] Optimize GeneralUtility path methods

The following methods are amongst the most frequently called ones:
  • getFileAbsFileName()
  • validPathStr()
  • isAllowedAbsPath()
  • verifyFilenameAgainstDenyPattern()

They can be optimized to return early, save some variable assignments and
save some preg_match calls.

Change-Id: Id30b2f9b5a053d4267d9c24339f414821ba661ea
Resolves: #54525
Releases: 6.2
Reviewed-on: https://review.typo3.org/26505
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
Reviewed-by: Stefan Neufeind
Reviewed-by: Markus Klein
Tested-by: Markus Klein

History

#1 Updated by Gerrit Code Review almost 6 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/26505

#2 Updated by Gerrit Code Review almost 6 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/26505

#3 Updated by Gerrit Code Review almost 6 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/26505

#4 Updated by Gerrit Code Review almost 6 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/26505

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

#6 Updated by Gerrit Code Review almost 6 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/26505

#7 Updated by Gerrit Code Review almost 6 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/26505

#8 Updated by Gerrit Code Review almost 6 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/26505

#9 Updated by Georg Ringer almost 6 years ago

so what is the measured benefit?

#10 Updated by Michiel Roos almost 6 years ago

I'll post some stats this evening.

These methods are being called a lot during the frontend rendering and backend rendering. Parsing and concatenating JS and CSS and generating cache files etc.

But to give you a rough impression. These are the current call counts for an uncached backend request (/typo3/backend.php), right after clearing all cache:

Times are inclusive wall time.

TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath - 2.267 calls - 364,98 ms
TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr     - 2.315 calls - 168,77 ms
TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath        - 4.598 calls -  77,33 ms
TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath  -   608 calls -  23,03 ms

The total wall time was 10,43 s here . . . mostly taken by file_put_contents(), rename(), chgrp() etc.

Reduction in call times with the patch:

TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath - 67,30 ms
TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr     -  9,19 ms
TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath        - 33,97 ms
TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath  -  2,32 ms

#11 Updated by Michiel Roos almost 6 years ago

Here is a test for the isAbsPath function to get an impression: http://pastebin.com/0BqyVGrc

#12 Updated by Ernesto Baschny over 5 years ago

  • Target version changed from next-patchlevel to 6.2.0
  • Parent task set to #55078

#13 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/26505

#14 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/26505

#15 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/26505

#16 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/26505

#17 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/26505

#18 Updated by Michiel Roos over 5 years ago

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

#19 Updated by Riccardo De Contardi almost 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF