Bug #42723

Reflection\ObjectAccess consumes to much processing time

Added by Steffen Ritter over 2 years ago. Updated over 2 years ago.

Status:Resolved Start date:2012-11-06
Priority:Should have Due date:
Assigned To:- % Done:

100%

Category:Reflection
Target version:-
PHP Version: Complexity:
Has patch:Yes Affected Flow version:Git master

Description

JsonView, Validation, Serialisation and many other parts of Flow use ObjectAccess to retrieve information about how to access properties within the current object.

getAvailableGetters for example is called thousands of times, when putting an object hirarchy of 150 fuel stations with each one address and 3 opening entries (therefore 750 objects in a nested hirarchy) first into validation and than output it as JSON.

After compile (e.g. php is running) - the properties of an Object are immutable (despite stdClass). Therefore the ObjectAccess class should use a runtime cache.


Related issues

related to TYPO3.Flow - Bug #46491: ObjectAccess::getProperty() does not work for getters in ... Resolved 2013-03-21

Associated revisions

Revision 3f176188
Added by Steffen Ritter over 2 years ago

[TASK] Add Runtime Cache to Reflection\ObjectAccess

Using Reflection\ObjectAccess during validation or f.e. JsonView in an
extensive way you soon will end up with thousands of calls to functions
of that class.

By adding a runtime cache this can be sped up.

Change-Id: I2abbbd5924cd0177ad8a31cb01c2953dd5ba39fd
Resolves: #42723
Releases: master

Revision 392020a6
Added by Bastian Waidelich over 2 years ago

[BUGFIX] fix ObjectAccess::getProperty() for getters in ArrayAccess objects

With I2abbbd5924cd0177ad8a31cb01c2953dd5ba39fd a regression was introduced
that prevented ObjectAccess::getProperty() to work on objects implementing ArrayAccess
and providing custom getters.

Code to reproduce:
\TYPO3\Flow\Reflection\ObjectAccess::getProperty(new \ArrayObject(), 'iteratorClass')

expected: "ArrayIterator"
actual: Exception

This change fixes this by checking arrays and ArrayAccess objects separately.

Change-Id: I31355c9b4ace868cff7d5ea1c4e1b3735b1225f6
Fixes: #46491
Related: #42723
Releases: master

Revision c0c6c2c2
Added by Steffen Ritter over 2 years ago

[TASK] Add Runtime Cache to Reflection\ObjectAccess

Using Reflection\ObjectAccess during validation or f.e. JsonView in an
extensive way you soon will end up with thousands of calls to functions
of that class.

By adding a runtime cache this can be sped up.

Change-Id: I2abbbd5924cd0177ad8a31cb01c2953dd5ba39fd
Resolves: #42723
Releases: master

Revision cf1e9e3e
Added by Bastian Waidelich over 2 years ago

[BUGFIX] fix ObjectAccess::getProperty() for getters in ArrayAccess objects

With I2abbbd5924cd0177ad8a31cb01c2953dd5ba39fd a regression was introduced
that prevented ObjectAccess::getProperty() to work on objects implementing ArrayAccess
and providing custom getters.

Code to reproduce:
\TYPO3\Flow\Reflection\ObjectAccess::getProperty(new \ArrayObject(), 'iteratorClass')

expected: "ArrayIterator"
actual: Exception

This change fixes this by checking arrays and ArrayAccess objects separately.

Change-Id: I31355c9b4ace868cff7d5ea1c4e1b3735b1225f6
Fixes: #46491
Related: #42723
Releases: master

History

#1 Updated by Gerrit Code Review over 2 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16234

#2 Updated by Steffen Ritter over 2 years ago

btw: this reduces the execution time within ObjectAccess from > 40% to below 10% in the given example

#3 Updated by Gerrit Code Review over 2 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16234

#4 Updated by Gerrit Code Review over 2 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16234

#5 Updated by Gerrit Code Review over 2 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16234

#6 Updated by Gerrit Code Review over 2 years ago

Patch set 5 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16234

#7 Updated by Gerrit Code Review over 2 years ago

Patch set 6 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16234

#8 Updated by Gerrit Code Review over 2 years ago

Patch set 7 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16234

#9 Updated by Karsten Dambekalns over 2 years ago

  • Affected Flow version changed from Git 1.2 (master) to Git master

#10 Updated by Bastian Waidelich over 2 years ago

I didn't manage to test this while it was hot, but now I realized that this breaks the Form framework (and probably some more).
In my case FormRuntime::getCurrentPage() always returns NULL – because FormRuntime implements \ArrayAccess but $formRuntime['currentPage'] returns FALSE.

To reproduce create a class extending \ArrayAccess and providing some additional custom getter. This getter can't be called via ObjectAccess

#11 Updated by Bastian Waidelich over 2 years ago

A simple test case to reproduce this:

1$arrayObject = new \ArrayObject();
2var_dump($arrayObject->getIteratorClass());
3var_dump(\TYPO3\Flow\Reflection\ObjectAccess::getProperty($arrayObject, 'iteratorClass'));

Should output "ArrayIterator" twice, but the second time an exception #1263391473: The property "iteratorClass" on the subject was not accessible is thrown.
Commenting out 113 & 114 in ObjectAccess fixes this issue for me.

I'll write tests and push a follow up

#12 Updated by Gerrit Code Review over 2 years ago

Patch set 1 for branch composer has been pushed to the review server.
It is available at https://review.typo3.org/19347

#13 Updated by Steffen Ritter over 2 years ago

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

Also available in: Atom PDF