From 7189a3ebffb7b7bd59bce510753bc6d97988eacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wilczy=C5=84ski?= Date: Tue, 26 Aug 2025 12:04:08 +0200 Subject: [PATCH] fix(model): consider number of CPU cores when calculating hashers on interactive OS (#10284) (#10286) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the number of hashers is always set to 1 on interactive operating systems, which are defined as Windows, macOS, iOS, and Android. However, with modern multicore CPUs, it does not make much sense to limit performance so much. For example, without this fix, a CPU with 16 cores / 32 threads is still limited to using just a single thread to hash files per folder, which may severely affect its performance. For this reason, instead of using a fixed value, calculate the number dynamically, so that it equals one-fourth of the total number of CPU cores. This way, the value of hashes will still end up being just 1 on a slower 4-thread CPU, but it will be allowed to take larger values when the number of threads is higher, increasing hashing performance in the process. Signed-off-by: Tomasz WilczyƄski Co-authored-by: Jakob Borg --- lib/model/model.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/model/model.go b/lib/model/model.go index c78ed4e48..0bc0a12c1 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -2561,16 +2561,17 @@ func (m *model) numHashers(folder string) int { return folderCfg.Hashers } + numCpus := runtime.GOMAXPROCS(-1) if build.IsWindows || build.IsDarwin || build.IsIOS || build.IsAndroid { // Interactive operating systems; don't load the system too heavily by // default. - return 1 + numCpus = max(1, numCpus/4) } // For other operating systems and architectures, lets try to get some // work done... Divide the available CPU cores among the configured // folders. - if perFolder := runtime.GOMAXPROCS(-1) / numFolders; perFolder > 0 { + if perFolder := numCpus / numFolders; perFolder > 0 { return perFolder }