Req #72224 [Com]: Optimize reflection initialization

From: Date: Mon, 23 May 2016 20:20:59 +0000
Subject: Req #72224 [Com]: Optimize reflection initialization
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201249@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72224&edit=1

 ID:                 72224
 Comment by:         dmri87 at hotmail dot com
 Reported by:        dmri87 at hotmail dot com
 Summary:            Optimize reflection initialization
 Status:             Feedback
 Type:               Feature/Change Request
 Package:            Reflection related
 PHP Version:        7.0.7RC1
 Block user comment: N
 Private report:     N

 New Comment:

The example would probably make more sense if I assigned the object to a variable. 

Also notice how I left out the constructor. I'd expect ReflectionClass to compare in
performance to the creation of an object without calling its constructor.

Sorry for the multiple replies.


Previous Comments:
------------------------------------------------------------------------
[2016-05-23 20:03:46] dmri87 at hotmail dot com

Literally any reflection object, krakjoe.

It is comparable in performance to the creation of other objects, sure, but it is too slow
considered that reflection is basically just static information.

For instance, why is this 6 (!!!) times slower than creating the actual object?

class A{}

for($i = 0; $i < 1000000; $i++){
    new A();
} // 0.3150179386 seconds

for($i = 0; $i < 1000000; $i++){
    new ReflectionClass('A');
} // 1.9061090946 seconds

------------------------------------------------------------------------
[2016-05-20 19:29:35] krakjoe@php.net

I've flicked through the source code of the most common reflector constructors, and I see
nothing that is obviously causing such problems.

Can you provide some example code that behaves extra ordinarily, perhaps that will help me to
understand better ?

------------------------------------------------------------------------
[2016-05-16 14:18:20] dmri87 at hotmail dot com

Description:
------------
PHP should improve the creation of Reflection objects.

Almost literally any library or framework using Reflection non trivially I've encountered
implements its own Reflection objects caching mechanism. That because creating such objects is
incredibly expensive and it's way more expensive than caching them all, even if thousands of
them. I had to do the same to keep performance acceptable.

PHP should do this internally if possible, or try to optimize something, because again, the amount
of times I've seen this is incredible and it's a clear sign the creation of such object is
just too slow.

Just to be clear (sorry if I sound harsh but I actually just want to be clear) Reflection
object's creation performance is a problem even for those that are using it trivially. I
don't think it's acceptable if the creation of few dozens of these objects turns out to be
an important bottleneck for applications that would otherwise be extremely fast.

Thank you for reading and double thank you if you intend to work on this.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72224&edit=1


Thread (9 messages)

« previous php.bugs (#201249) next »