summaryrefslogtreecommitdiff
path: root/crates/typst-cli
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-06-10 15:28:40 +0200
committerGitHub <noreply@github.com>2024-06-10 13:28:40 +0000
commit7fa86eed0eca9b529d71d4006f389a753467e54a (patch)
treeeeb4a0cd5a82e30b1852312f3eec1c6269a893b8 /crates/typst-cli
parenta68a241570eca6d46f916e3ee103664a4eb79333 (diff)
Basic multi-threading (#4366)
Diffstat (limited to 'crates/typst-cli')
-rw-r--r--crates/typst-cli/src/args.rs5
-rw-r--r--crates/typst-cli/src/world.rs5
2 files changed, 10 insertions, 0 deletions
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<usize>,
}
/// 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<Self, WorldCreationError> {
+ // 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,