Skip to content

Reflecting same class trees leads to extremely high amount of repeated parsing/AST traversal and therefore overhead #417

Closed
@Ocramius

Description

@Ocramius

To reproduce, something like this would probably suffice:

$sourceLocator = new StringSourceLocator(
<<<'PHP'
<?php

class A {}
class B extends A {}
class C extends A {}
PHP
    ,
    (new BetterReflection())->astLocator()
);

$reflector = new ClassReflector($sourceLocator);

// now put a breakpoint in `ClassReflector#reflect()` and notice that it is being called 4 times instead of 3:

$b = $reflector->reflect('B');
$b->getParentClassNames();
$c = $reflector->reflect('C');
$c->getParentClassNames();

This is because the various internal components don't cache the reflections.

What we can do:

  • make the ClassReflector and the FunctionReflector keep an internal cache by default (not so nice)
  • make a CachedReflector that caches based on the requested identifier (not so easy due to delegation logic happening in the ClassReflector internals)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions