From c917f4ec78102fa93f25fc58d8f714124f6fe823 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 19 Aug 2025 15:00:10 +0200 Subject: [PATCH] nix/sigs: remove CopySigs thread pool we don't have benchmarks for this one, but a 10x improvement seems likely. Change-Id: I76f4e9c9ebff86fd7d451ed7e125ab309011457e --- lix/nix/sigs.cc | 67 ++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/lix/nix/sigs.cc b/lix/nix/sigs.cc index a8ac6f933..5a3973a8e 100644 --- a/lix/nix/sigs.cc +++ b/lix/nix/sigs.cc @@ -1,7 +1,10 @@ #include "lix/libcmd/command.hh" #include "lix/libmain/shared.hh" +#include "lix/libstore/path.hh" #include "lix/libstore/store-api.hh" +#include "lix/libutil/async-collect.hh" #include "lix/libutil/async.hh" +#include "lix/libutil/result.hh" #include "lix/libutil/thread-pool.hh" #include "lix/libutil/signals.hh" #include "sigs.hh" @@ -41,48 +44,48 @@ struct CmdCopySigs : StorePathsCommand for (auto & s : substituterUris) substituters.push_back(aio().blockOn(openStore(s))); - ThreadPool pool{"CopySigs pool"}; + size_t added = 0; - std::atomic added{0}; + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) + auto doPath = [&](const StorePath & storePath) -> kj::Promise> { + try { + auto info = TRY_AWAIT(store->queryPathInfo(storePath)); - auto doPath = [&](AsyncIoRoot & aio, const Path & storePathS) { - auto storePath = store->parseStorePath(storePathS); + StringSet newSigs; - auto info = aio.blockOn(store->queryPathInfo(storePath)); + for (auto & store2 : substituters) { + try { + auto info2 = TRY_AWAIT(store2->queryPathInfo(info->path)); - StringSet newSigs; + /* Don't import signatures that don't match this + binary. */ + if (info->narHash != info2->narHash || info->narSize != info2->narSize + || info->references != info2->references) + { + continue; + } - for (auto & store2 : substituters) { - try { - auto info2 = aio.blockOn(store2->queryPathInfo(info->path)); - - /* Don't import signatures that don't match this - binary. */ - if (info->narHash != info2->narHash || - info->narSize != info2->narSize || - info->references != info2->references) - continue; - - for (auto & sig : info2->sigs) - if (!info->sigs.count(sig)) - newSigs.insert(sig); - } catch (InvalidPath &) { + for (auto & sig : info2->sigs) { + if (!info->sigs.count(sig)) { + newSigs.insert(sig); + } + } + } catch (InvalidPath &) { + } } - } - if (!newSigs.empty()) { - aio.blockOn(store->addSignatures(storePath, newSigs)); - added += newSigs.size(); + if (!newSigs.empty()) { + TRY_AWAIT(store->addSignatures(storePath, newSigs)); + added += newSigs.size(); + } + + co_return result::success(); + } catch (...) { + co_return result::current_exception(); } }; - for (auto & storePath : storePaths) { - pool.enqueueWithAio( - std::bind(doPath, std::placeholders::_1, store->printStorePath(storePath)) - ); - } - - pool.process(); + aio().blockOn(asyncSpread(storePaths, doPath)); printInfo("imported %d signatures", added); }