From 2091ecd738923281ec176303e509b1e765c5b28b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 21 Feb 2026 10:17:54 +0100 Subject: [PATCH 1/4] Faster MutatingScope->getNodeKey() --- src/Analyser/MutatingScope.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 7829231448..78b7788d52 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -917,8 +917,12 @@ public function getScopeNativeType(Expr $expr): Type private function getNodeKey(Expr $node): string { - $key = $this->exprPrinter->printExpr($node); + // perf optimize for the most common path + if ($node instanceof Variable) { + return '$'.$node->name; + } + $key = $this->exprPrinter->printExpr($node); $attributes = $node->getAttributes(); if ( $node instanceof Node\FunctionLike From dc55cd3454d4363c479ab3e7fb6b46a75f32a744 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 21 Feb 2026 10:24:12 +0100 Subject: [PATCH 2/4] cs --- src/Analyser/MutatingScope.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 78b7788d52..0864cc934c 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -919,7 +919,7 @@ private function getNodeKey(Expr $node): string { // perf optimize for the most common path if ($node instanceof Variable) { - return '$'.$node->name; + return '$' . $node->name; } $key = $this->exprPrinter->printExpr($node); From 242f09a65e6a34cbee9f9d47fb52ece780626d4c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 21 Feb 2026 10:28:26 +0100 Subject: [PATCH 3/4] Update MutatingScope.php --- src/Analyser/MutatingScope.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 0864cc934c..296e3f1e7e 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -918,7 +918,7 @@ public function getScopeNativeType(Expr $expr): Type private function getNodeKey(Expr $node): string { // perf optimize for the most common path - if ($node instanceof Variable) { + if ($node instanceof Variable && !$node->name instanceof Expr) { return '$' . $node->name; } From 90d7edd2f63ae94db8b245a2c8806846c2cd462d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 24 Feb 2026 10:21:23 +0100 Subject: [PATCH 4/4] Update ExprPrinter.php --- src/Node/Printer/ExprPrinter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Node/Printer/ExprPrinter.php b/src/Node/Printer/ExprPrinter.php index 8d31c9344d..33de36f211 100644 --- a/src/Node/Printer/ExprPrinter.php +++ b/src/Node/Printer/ExprPrinter.php @@ -20,6 +20,11 @@ public function __construct(private Printer $printer) public function printExpr(Expr $expr): string { + // perf optimize for the most common path + if ($expr instanceof Expr\Variable && !$expr->name instanceof Expr) { + return '$' . $expr->name; + } + /** @var string|null $exprString */ $exprString = $expr->getAttribute(self::ATTRIBUTE_CACHE_KEY); if ($exprString === null) {