From 7fa86eed0eca9b529d71d4006f389a753467e54a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 10 Jun 2024 15:28:40 +0200 Subject: Basic multi-threading (#4366) --- crates/typst-cli/src/args.rs | 5 +++++ crates/typst-cli/src/world.rs | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'crates/typst-cli') diff --git a/crates/typst-cli/src/args.rs b/crates/typst-cli/src/args.rs index cf8a2c6f..9648d8ef 100644 --- a/crates/typst-cli/src/args.rs +++ b/crates/typst-cli/src/args.rs @@ -217,6 +217,11 @@ pub struct SharedArgs { /// Arguments related to storage of packages in the system #[clap(flatten)] pub package_storage_args: PackageStorageArgs, + + /// Number of parallel jobs spawned during compilation, + /// defaults to number of CPUs. + #[clap(long, short)] + pub jobs: Option, } /// Arguments related to where packages are stored in the system. diff --git a/crates/typst-cli/src/world.rs b/crates/typst-cli/src/world.rs index 9748d9c5..8e8b305f 100644 --- a/crates/typst-cli/src/world.rs +++ b/crates/typst-cli/src/world.rs @@ -56,6 +56,11 @@ pub struct SystemWorld { impl SystemWorld { /// Create a new system world. pub fn new(command: &SharedArgs) -> Result { + // Set up the thread pool. + if let Some(jobs) = command.jobs { + rayon::ThreadPoolBuilder::new().num_threads(jobs).build_global().ok(); + } + // Resolve the system-global input path. let input = match &command.input { Input::Stdin => None, -- cgit v1.2.3