Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow config to define thread count #7442

Merged
merged 6 commits into from Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/running_psalm/configuration.md
Expand Up @@ -396,6 +396,14 @@ 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 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.
orklah marked this conversation as resolved.
Show resolved Hide resolved


## 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
13 changes: 12 additions & 1 deletion 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::useThreads($options, $in_ci, $config);

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

Expand Down Expand Up @@ -1337,4 +1337,15 @@ private static function getHelpText(): string

HELP;
}

private static function useThreads(array $options, bool $in_ci, Config $config): int
{
$threads = self::detectThreads($options, $in_ci);

if ($config->threads && $config->threads<$threads) {
$threads = $config->threads;
}

return $threads;
}
}