Skip to content

Commit

Permalink
Optimize memory consumption in ResultCacheManager
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Oct 14, 2023
1 parent bd3f7f3 commit b5bac62
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,19 +601,6 @@ private function save(
$invertedDependencies[$file]['dependentFiles'] = $dependentFiles;
}

$template = "<?php declare(strict_types = 1);
return [
'lastFullAnalysisTime' => %s,
'meta' => %s,
'projectExtensionFiles' => %s,
'errorsCallback' => static function (): array { return %s; },
'collectedDataCallback' => static function (): array { return %s; },
'dependencies' => %s,
'exportedNodesCallback' => static function (): array { return %s; },
];
";

ksort($exportedNodes);

$file = $this->cacheFilePath;
Expand All @@ -624,16 +611,18 @@ private function save(

FileWriter::write(
$file,
sprintf(
$template,
var_export($lastFullAnalysisTime, true),
var_export($meta, true),
var_export($this->getProjectExtensionFiles($projectConfigArray, $dependencies), true),
var_export($errors, true),
var_export($collectedData, true),
var_export($invertedDependencies, true),
var_export($exportedNodes, true),
),
"<?php declare(strict_types = 1);
return [
'lastFullAnalysisTime' => " . var_export($lastFullAnalysisTime, true) . ",
'meta' => " . var_export($meta, true) . ",
'projectExtensionFiles' => " . var_export($this->getProjectExtensionFiles($projectConfigArray, $dependencies), true) . ",
'errorsCallback' => static function (): array { return " . var_export($errors, true) . "; },
'collectedDataCallback' => static function (): array { return " . var_export($collectedData, true) . "; },
'dependencies' => " . var_export($invertedDependencies, true) . ",
'exportedNodesCallback' => static function (): array { return " . var_export($exportedNodes, true) . '; },
];
',
);
}

Expand Down

0 comments on commit b5bac62

Please sign in to comment.