Skip to content

Commit

Permalink
Merge pull request #7442 from M1ke/m1ke/config-threads
Browse files Browse the repository at this point in the history
Allow config to define thread count
  • Loading branch information
orklah committed Jan 20, 2022
2 parents 1ff3161 + 6107148 commit 2aeaade
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/running_psalm/configuration.md
Expand Up @@ -396,6 +396,13 @@ Whether or not to allow `require`/`include` calls in your PHP. Defaults to `true
```
Allows you to hard-code a serializer for Psalm to use when caching data. By default, Psalm uses `ext-igbinary` *if* the version is greater than or equal to 2.0.5, otherwise it defaults to PHP's built-in serializer.

#### threads
```xml
<psalm
threads="[int]"
>
```
Allows you to hard-code the number of threads Psalm will use (similar to `--threads` on the command line). This value will be used in place of detecting threads from the host machine, but will be overridden by using `--threads` or `--debug` (which sets threads to 1) on the command line

## Project settings

Expand Down
7 changes: 7 additions & 0 deletions src/Psalm/Config.php
Expand Up @@ -563,6 +563,9 @@ class Config
*/
public $internal_stubs = [];

/** @var ?int */
public $threads;

protected function __construct()
{
self::$instance = $this;
Expand Down Expand Up @@ -1222,6 +1225,10 @@ private static function fromXmlAndPaths(
}
}

if (isset($config_xml->threads)) {
$config->threads = (int)$config_xml->threads;
}

return $config;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Psalm/Internal/Cli/Psalm.php
Expand Up @@ -249,7 +249,7 @@ public static function run(array $argv): void
$options['long-progress'] = true;
}

$threads = self::detectThreads($options, $in_ci);
$threads = self::detectThreads($options, $config, $in_ci);

self::emitMacPcreWarning($options, $threads);

Expand Down Expand Up @@ -913,12 +913,14 @@ private static function restart(array $options, Config $config, int $threads): v
}
}

private static function detectThreads(array $options, bool $in_ci): int
private static function detectThreads(array $options, Config $config, bool $in_ci): int
{
if (isset($options['threads'])) {
$threads = (int)$options['threads'];
} elseif (isset($options['debug']) || $in_ci) {
$threads = 1;
} elseif ($config->threads) {
$threads = $config->threads;
} else {
$threads = max(1, ProjectAnalyzer::getCpuCount() - 1);
}
Expand Down

0 comments on commit 2aeaade

Please sign in to comment.