From d15a0cd9ebbd4ebd51a52f7547a18a66c52ef411 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 29 Jul 2025 15:15:37 +0100 Subject: [PATCH] env_config: add `auto` option for `download_concurrency` This will allow the user to set `HOMEBREW_DOWNLOAD_CONCURRENCY` to `auto` to have Homebrew use the number of cores on the machine * 2. --- Library/Homebrew/env_config.rb | 13 ++++++++++--- Library/Homebrew/env_config.rbi | 8 ++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 Library/Homebrew/env_config.rbi diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 6a2a558232..1d363b5d57 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -634,9 +634,16 @@ module Homebrew sig { returns(Integer) } def download_concurrency # TODO: document this variable when ready to publicly announce it. - concurrency = ENV.fetch("HOMEBREW_DOWNLOAD_CONCURRENCY", 1).to_i - concurrency = 1 if concurrency <= 1 - concurrency + concurrency = ENV.fetch("HOMEBREW_DOWNLOAD_CONCURRENCY", 1) + concurrency = if concurrency == "auto" + require "os" + require "hardware" + Hardware::CPU.cores * 2 + else + concurrency.to_i + end + + [concurrency, 1].max end end end diff --git a/Library/Homebrew/env_config.rbi b/Library/Homebrew/env_config.rbi new file mode 100644 index 0000000000..d6e994727e --- /dev/null +++ b/Library/Homebrew/env_config.rbi @@ -0,0 +1,8 @@ +# typed: strict +# frozen_string_literal: true + +module Homebrew + module EnvConfig + include Kernel + end +end