Skip to content

Commit 709654e

Browse files
ondrejmirtesclaude
andcommitted
Make the member cache LRU limit configurable as cache.memberCacheKeysMax
Replaces the MEMBER_CACHE_KEYS_MAX constant with a parameter alongside the other cache limits; 0 means unlimited, same as cache.phpStormStubsNodesCountMax. The 2048 default is confirmed by a sweep on a 2,358-file project (8 workers, result cache cleared, error output byte-identical across all runs): unlimited costs 9.02 GB summed worker peaks, any limit in 512-2048 lands on the same 8.8 GB plateau, and 128-256 give the savings back through evict-recompute churn. No limit-dependent time cost: wall and user CPU varied together across limits (machine scheduling noise), never with the limit. Self-analysis is flat in both time and memory at every limit down to 64. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P8cNW3DZDEJjeBK2WXqgP7
1 parent 06fbac4 commit 709654e

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎conf/config.neon‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ parameters:
127127
resolvedPhpDocBlockCacheCountMax: 2048
128128
nameScopeMapMemoryCacheCountMax: 512
129129
phpStormStubsNodesCountMax: 128
130+
memberCacheKeysMax: 2048
130131
reportUnmatchedIgnoredErrors: true
131132
reportIgnoresWithoutComments: false
132133
typeAliases: []

‎conf/parametersSchema.neon‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ parametersSchema:
150150
nodesByStringCountMax: int(),
151151
resolvedPhpDocBlockCacheCountMax: int(),
152152
nameScopeMapMemoryCacheCountMax: int(),
153-
phpStormStubsNodesCountMax: int()
153+
phpStormStubsNodesCountMax: int(),
154+
memberCacheKeysMax: int()
154155
])
155156
reportUnmatchedIgnoredErrors: bool()
156157
reportIgnoresWithoutComments: bool()

‎conf/services.neon‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ services:
5959
arguments:
6060
parser: @defaultAnalysisParser
6161
inferPrivatePropertyTypeFromConstructor: %inferPrivatePropertyTypeFromConstructor%
62+
memberCacheKeysMax: %cache.memberCacheKeysMax%
6263

6364
-
6465
class: PHPStan\Reflection\Annotations\AnnotationsMethodsClassReflectionExtension

‎src/Reflection/Php/PhpClassReflectionExtension.php‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@
7474
final class PhpClassReflectionExtension
7575
{
7676

77-
private const MEMBER_CACHE_KEYS_MAX = 2048;
78-
7977
/** @var array<string, true> shared LRU over the member cache keys below; first entry = least recently used */
8078
private array $memberCacheOrder = [];
8179

@@ -114,14 +112,15 @@ public function __construct(
114112
private ParameterAllowedConstantsMapProvider $allowedConstantsMapProvider,
115113
private bool $inferPrivatePropertyTypeFromConstructor,
116114
private PhpVersion $phpVersion,
115+
private int $memberCacheKeysMax,
117116
)
118117
{
119118
}
120119

121120
/**
122121
* Moves the cache key to the most-recently-used position of the shared LRU governing
123122
* all four member caches; evicts the least recently used key's entries from all of
124-
* them once the limit is reached.
123+
* them once the limit is reached. A limit of 0 means unlimited.
125124
*
126125
* Replaces the former evictPrivateSymbols(): instead of dropping only private members
127126
* of the just-analysed class (public/protected members accumulated for the whole
@@ -137,7 +136,7 @@ private function touchMemberCacheKey(string $cacheKey): void
137136
}
138137

139138
$this->memberCacheOrder[$cacheKey] = true;
140-
if (count($this->memberCacheOrder) <= self::MEMBER_CACHE_KEYS_MAX) {
139+
if ($this->memberCacheKeysMax === 0 || count($this->memberCacheOrder) <= $this->memberCacheKeysMax) {
141140
return;
142141
}
143142

0 commit comments

Comments
 (0)