From b7c438bf97c618d8b59c15ef23301ec0d357a23b Mon Sep 17 00:00:00 2001 From: Brown Date: Wed, 17 Oct 2018 18:11:02 -0400 Subject: [PATCH] Fix slowness when invalidating heavily-used files --- src/Psalm/Checker/ProjectChecker.php | 15 +++++++++------ src/Psalm/Codebase.php | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Psalm/Checker/ProjectChecker.php b/src/Psalm/Checker/ProjectChecker.php index ca22810b9..d06f611af 100644 --- a/src/Psalm/Checker/ProjectChecker.php +++ b/src/Psalm/Checker/ProjectChecker.php @@ -712,7 +712,7 @@ class ProjectChecker * * @return array */ - public function getReferencedFilesFromDiff(array $diff_files) + public function getReferencedFilesFromDiff(array $diff_files, bool $include_referencing_files = true) { $all_inherited_files_to_check = $diff_files; @@ -720,17 +720,20 @@ class ProjectChecker $diff_file = array_shift($diff_files); $dependent_files = $this->file_reference_provider->getFilesInheritingFromFile($diff_file); + $new_dependent_files = array_diff($dependent_files, $all_inherited_files_to_check); - $all_inherited_files_to_check += $new_dependent_files; - $diff_files += $new_dependent_files; + $all_inherited_files_to_check = array_merge($all_inherited_files_to_check, $new_dependent_files); + $diff_files = array_merge($diff_files, $new_dependent_files); } $all_files_to_check = $all_inherited_files_to_check; - foreach ($all_inherited_files_to_check as $file_name) { - $dependent_files = $this->file_reference_provider->getFilesReferencingFile($file_name); - $all_files_to_check = array_merge($dependent_files, $all_files_to_check); + if ($include_referencing_files) { + foreach ($all_inherited_files_to_check as $file_name) { + $dependent_files = $this->file_reference_provider->getFilesReferencingFile($file_name); + $all_files_to_check = array_merge($dependent_files, $all_files_to_check); + } } return array_combine($all_files_to_check, $all_files_to_check); diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index e9eb984e2..613215534 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -245,7 +245,7 @@ class Codebase } } - $referenced_files = $project_checker->getReferencedFilesFromDiff($diff_files); + $referenced_files = $project_checker->getReferencedFilesFromDiff($diff_files, false); foreach ($diff_files as $diff_file_path) { $this->invalidateInformationForFile($diff_file_path);