Introduce TY_MAX_PARALLELISM environment variable (#17830)

This commit is contained in:
Micha Reiser 2025-05-04 16:27:15 +02:00 committed by GitHub
parent 68e32c103f
commit e95130ad80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 78 additions and 36 deletions

View file

@ -10,7 +10,9 @@ use anyhow::{anyhow, Context};
use clap::Parser;
use colored::Colorize;
use crossbeam::channel as crossbeam_channel;
use rayon::ThreadPoolBuilder;
use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig, Severity};
use ruff_db::max_parallelism;
use ruff_db::system::{OsSystem, SystemPath, SystemPathBuf};
use salsa::plumbing::ZalsaDatabase;
use ty_project::metadata::options::Options;
@ -25,6 +27,8 @@ mod python_version;
mod version;
pub fn main() -> ExitStatus {
setup_rayon();
run().unwrap_or_else(|error| {
use std::io::Write;
@ -392,3 +396,11 @@ fn set_colored_override(color: Option<TerminalColor>) {
}
}
}
/// Initializes the global rayon thread pool to never use more than `TY_MAX_PARALLELISM` threads.
fn setup_rayon() {
ThreadPoolBuilder::default()
.num_threads(max_parallelism().get())
.build_global()
.unwrap();
}