1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Make Psalm faster when there aren’t any changes whatsoever

This commit is contained in:
Brown 2020-03-31 22:22:34 -04:00
parent d5f43e52e7
commit 4ef7cb50a5
2 changed files with 34 additions and 15 deletions

View File

@ -309,12 +309,26 @@ class ProjectAnalyzer
return $report_options;
}
private function visitAutoloadFiles()
{
$start_time = microtime(true);
$this->config->visitComposerAutoloadFiles($this, $this->progress);
$now_time = microtime(true);
$this->progress->debug(
'Visiting autoload files took ' . number_format($now_time - $start_time, 3) . 's' . "\n"
);
}
/**
* @param string|null $address
* @return void
*/
public function server($address = '127.0.0.1:12345', bool $socket_server_mode = false)
{
$this->visitAutoloadFiles();
$this->codebase->diff_methods = true;
$this->file_reference_provider->loadReferenceCache();
$this->codebase->enterServerMode();
@ -485,6 +499,8 @@ class ProjectAnalyzer
$this->codebase->scanner->addFilesToDeepScan($this->project_files);
}
$diff_no_files = false;
if ($diff_files === null
|| $deleted_files === null
|| count($diff_files) > 200
@ -510,19 +526,27 @@ class ProjectAnalyzer
$this->checkDiffFilesWithConfig($this->config, $file_list);
$this->config->initializePlugins($this);
if ($file_list) {
$this->visitAutoloadFiles();
$this->codebase->scanFiles($this->threads);
$this->config->initializePlugins($this);
$this->codebase->scanFiles($this->threads);
} else {
$diff_no_files = true;
}
}
}
$this->config->visitStubFiles($this->codebase, $this->progress);
if (!$diff_no_files) {
$this->config->visitStubFiles($this->codebase, $this->progress);
$plugin_classes = $this->config->after_codebase_populated;
$plugin_classes = $this->config->after_codebase_populated;
if ($plugin_classes) {
foreach ($plugin_classes as $plugin_fq_class_name) {
$plugin_fq_class_name::afterCodebasePopulated($this->codebase);
if ($plugin_classes) {
foreach ($plugin_classes as $plugin_fq_class_name) {
$plugin_fq_class_name::afterCodebasePopulated($this->codebase);
}
}
}
@ -1055,6 +1079,8 @@ class ProjectAnalyzer
*/
public function checkPaths(array $paths_to_check)
{
$this->visitAutoloadFiles();
foreach ($paths_to_check as $path) {
$this->progress->debug('Checking ' . $path . "\n");

View File

@ -209,6 +209,7 @@ $vendor_dir = getVendorDir($current_dir);
$first_autoloader = requireAutoloaders($current_dir, isset($options['r']), $vendor_dir);
if (array_key_exists('v', $options)) {
echo 'Psalm ' . PSALM_VERSION . PHP_EOL;
exit;
@ -433,8 +434,6 @@ $find_references_to = isset($options['find-references-to']) && is_string($option
? $options['find-references-to']
: null;
if (isset($options['shepherd'])) {
if (is_string($options['shepherd'])) {
$config->shepherd_host = $options['shepherd'];
@ -548,12 +547,6 @@ if ($type_map_location) {
$start_time = microtime(true);
$config->visitComposerAutoloadFiles($project_analyzer, $progress);
$now_time = microtime(true);
$progress->debug('Visiting autoload files took ' . number_format($now_time - $start_time, 3) . 's' . "\n");
if (array_key_exists('debug-by-line', $options)) {
$project_analyzer->debug_lines = true;
}