From 555933315d2646b298ebeda91c0f3dbf07b28657 Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Tue, 15 Jul 2025 11:21:00 +0800 Subject: [PATCH] Only start offload worker thread when there's more than 1 core (#2956) * Only start offload worker thread when there's more than 1 core * Write changelog --- CHANGELOG.md | 1 + src/bin/bat/app.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbf60912..29ddf751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - CICD: CICD: replace windows-2019 runners with windows-2025 #3339 (@cyqsimon) - Build script: replace string-based codegen with quote-based codegen #3340 (@cyqsimon) - Improve code coverage of `--list-languages` parameter #2942 (@sblondon) +- Only start offload worker thread when there's more than 1 core #2956 (@cyqsimon) ## Syntaxes diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 946ce5b1..0474e120 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -3,6 +3,7 @@ use std::env; use std::io::IsTerminal; use std::path::{Path, PathBuf}; use std::str::FromStr; +use std::thread::available_parallelism; use crate::{ clap_app, @@ -149,7 +150,9 @@ impl App { // start building glob matchers for builtin mappings immediately // this is an appropriate approach because it's statistically likely that // all the custom mappings need to be checked - syntax_mapping.start_offload_build_all(); + if available_parallelism()?.get() > 1 { + syntax_mapping.start_offload_build_all(); + } if let Some(values) = self.matches.get_many::("ignored-suffix") { for suffix in values {