Skip to content

Commit 8a623d0

Browse files
ondrejmirtesclaude
andcommitted
Make the cap configurable via cache.resolvedLocalTypeAliasesCountMax
Default 2048, 0 disables eviction. Chosen from a cap sweep on a 2,358-file project (all LRU caps set to the sweep value, error output identical at every point): memory is U-shaped in the cap — 936.5 MB at 512, 880.5 MB at 2048, 930.5 MB uncapped — because too-small caps recreate evicted object graphs as duplicates while the old ones are still pinned by sibling caches, and too-large caps converge to unbounded retention. Elapsed time shows no trend across the whole range (84-101 s noise band). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NrTvR9j1mW2NNNC8RkuTsF
1 parent fda77dc commit 8a623d0

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

‎conf/config.neon‎

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

‎conf/parametersSchema.neon‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ parametersSchema:
151151
resolvedPhpDocBlockCacheCountMax: int(),
152152
nameScopeMapMemoryCacheCountMax: int(),
153153
phpStormStubsNodesCountMax: int(),
154-
memberCacheKeysMax: int()
154+
memberCacheKeysMax: int(),
155+
resolvedLocalTypeAliasesCountMax: int()
155156
])
156157
reportUnmatchedIgnoredErrors: bool()
157158
reportIgnoresWithoutComments: bool()

‎src/Testing/PHPStanTestCase.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public static function createTypeAliasResolver(array $globalTypeAliases, Reflect
137137
$container->getByType(TypeStringResolver::class),
138138
$container->getByType(TypeNodeResolver::class),
139139
$reflectionProvider,
140+
0,
140141
);
141142
}
142143

‎src/Type/UsefulTypeAliasResolver.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
final class UsefulTypeAliasResolver implements TypeAliasResolver
1919
{
2020

21-
private const RESOLVED_LOCAL_TYPE_ALIASES_MAX = 2048;
22-
2321
/** @var array<string, Type> */
2422
private array $resolvedGlobalTypeAliases = [];
2523

@@ -41,6 +39,8 @@ public function __construct(
4139
private TypeStringResolver $typeStringResolver,
4240
private TypeNodeResolver $typeNodeResolver,
4341
private ReflectionProvider $reflectionProvider,
42+
#[AutowiredParameter(ref: '%cache.resolvedLocalTypeAliasesCountMax%')]
43+
private int $resolvedLocalTypeAliasesCountMax,
4444
)
4545
{
4646
}
@@ -128,7 +128,7 @@ private function resolveLocalTypeAlias(string $aliasName, NameScope $nameScope):
128128
}
129129

130130
$this->resolvedLocalTypeAliases[$aliasNameInClassScope] = $resolvedAliasType;
131-
if (count($this->resolvedLocalTypeAliases) > self::RESOLVED_LOCAL_TYPE_ALIASES_MAX) {
131+
if ($this->resolvedLocalTypeAliasesCountMax !== 0 && count($this->resolvedLocalTypeAliases) > $this->resolvedLocalTypeAliasesCountMax) {
132132
// resolved alias types transitively pin ClassReflections and their whole
133133
// reflection trees — evict the least recently used
134134
unset($this->resolvedLocalTypeAliases[array_key_first($this->resolvedLocalTypeAliases)]);

0 commit comments

Comments
 (0)