Skip to content

Commit 725b365

Browse files
committed
Slice the inProcess memory cache in FileTypeMapper
1 parent fe36e29 commit 725b365

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Type/FileTypeMapper.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class FileTypeMapper
5151
/** @var (true|callable(): NameScope|NameScope)[][] */
5252
private array $inProcess = [];
5353

54+
private int $inProcessCount = 0;
55+
5456
/** @var array<string, ResolvedPhpDocBlock> */
5557
private array $resolvedPhpDocBlockCache = [];
5658

@@ -104,7 +106,22 @@ public function getResolvedPhpDoc(
104106
return ResolvedPhpDocBlock::createEmpty();
105107
}
106108

109+
if ($this->inProcessCount >= 2048) {
110+
foreach ($this->inProcess as $file => $nameScopes) {
111+
foreach ($nameScopes as $key => $nameScope) {
112+
if ($nameScope === true) {
113+
continue;
114+
}
115+
116+
unset($this->inProcess[$file][$key]);
117+
$this->inProcessCount--;
118+
break;
119+
}
120+
}
121+
}
122+
107123
$this->inProcess[$fileName][$nameScopeKey] = $nameScopeMap[$nameScopeKey];
124+
$this->inProcessCount++;
108125
}
109126

110127
if ($this->inProcess[$fileName][$nameScopeKey] === true) { // PHPDoc has cyclic dependency

0 commit comments

Comments
 (0)