From f4e9de93b50fe8135d378830577cda687cae28ee Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Fri, 30 May 2025 17:17:52 +0200 Subject: WriteTargetCacheEntries: do not use quadratic many jobs When backing up target-cache entries we use parallelism at two dimensions, the independent cache entries and for each entry we retrieve the artifacts in parallel. If for each dimension we use the full amount of parallelism allowed, that gives a number of threads up to the square of the amount of parallelism specified by the user. Therefore, use in each dimension only the square root of the allowed parallelism keeping the total parallelism (up to rounding) within the specified range. --- src/buildtool/main/build_utils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/buildtool/main/build_utils.cpp') diff --git a/src/buildtool/main/build_utils.cpp b/src/buildtool/main/build_utils.cpp index 3b919ade..684d2dd1 100644 --- a/src/buildtool/main/build_utils.cpp +++ b/src/buildtool/main/build_utils.cpp @@ -14,6 +14,7 @@ #include "src/buildtool/main/build_utils.hpp" +#include #include #include #include @@ -160,6 +161,7 @@ void WriteTargetCacheEntries( TargetCache const& tc, Logger const* logger, LogLevel log_level) { + std::size_t sqrt_jobs = std::lround(std::ceil(std::sqrt(jobs))); if (strategy == TargetCacheWriteStrategy::Disable) { return; } @@ -171,7 +173,7 @@ void WriteTargetCacheEntries( } // set up writer map auto tc_writer_map = CreateTargetCacheWriterMap( - cache_targets, extra_infos, jobs, &apis, strategy, tc); + cache_targets, extra_infos, sqrt_jobs, &apis, strategy, tc); std::vector cache_targets_ids; cache_targets_ids.reserve(cache_targets.size()); for (auto const& [k, _] : cache_targets) { @@ -180,7 +182,7 @@ void WriteTargetCacheEntries( // write the target cache keys bool failed{false}; { - TaskSystem ts{jobs}; + TaskSystem ts{sqrt_jobs}; tc_writer_map.ConsumeAfterKeysReady( &ts, cache_targets_ids, -- cgit v1.2.3