Skip to content

Commit abc407c

Browse files
ondrejmirtesclaude
andcommitted
Memoize ClassReflection::getName()
The hottest call on the class: 2.3M calls on a src/Type self-analysis, each two adapter frames deep (Adapter\ReflectionClass::getName → BetterReflection ReflectionClass::getName). Single-process src/Type analysis: −1.3% user CPU, 6/6 alternating pairs, t=5.2. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SRLigetKoiZzYBe4iRQb3J
1 parent 477db09 commit abc407c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/Reflection/ClassReflection.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ final class ClassReflection
171171
/** @var array<string, bool> */
172172
private array $hasStaticPropertyCache = [];
173173

174+
/**
175+
* getName() is the hottest call on this class (millions per run), two adapter frames deep
176+
*
177+
* @var class-string|null
178+
*/
179+
private ?string $name = null;
180+
174181
/**
175182
* @param ReflectionClass|ReflectionEnum $reflection
176183
* @param (Closure(): ?ResolvedPhpDocBlock)|null $stubPhpDocBlockCallback
@@ -275,7 +282,7 @@ public function getParentClass(): ?ClassReflection
275282
*/
276283
public function getName(): string
277284
{
278-
return $this->reflection->getName();
285+
return $this->name ??= $this->reflection->getName();
279286
}
280287

281288
public function getDisplayName(bool $withTemplateTypes = true): string

0 commit comments

Comments
 (0)