-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Is your feature request related to a problem?
Currently nix store layer has a lot of ad-hoc callback-based API combined with rather unstructured usage of ThreadPool to prevent blocking on high-latency operations (like queryPathInfo). Callback-based API is hard to write and maintain.
There are a lot of use-cases that would benefit from having a single principled approach to asynchronous operations.
Some use-cases:
- Add paths to the store asynchronously #13798
- libutil: Use ThreadPool in computeClosure to parallelize promise resolution #14604
- Short-circuit computeFSClosure when copying #14569
nix/src/libstore/build/substitution-goal.cc
Lines 94 to 95 in 152e7e4
// FIXME: make async info = sub->queryPathInfo(subPath ? *subPath : storePath); nix/src/libstore/remote-fs-accessor.cc
Lines 30 to 31 in 152e7e4
/* FIXME: do this asynchronously. */ writeFile(makeCacheFile(hashPart, "nar"), nar); - 95bd5da
- Make number of parallel substituter queries configurable #5324
Proposed solution
Leverage C++20 stackless coroutines to replace ad-hoc async. This is what the Lix project has done with the kj-async framework. Our goal scheduling already uses raw C++20 coroutine primitives for build scheduling.
Since C++ standard library currently lacks well-supported facilities for "Task", "Generator" types (see std::generator in https://en.cppreference.com/w/cpp/compiler_support.html). "Task" type is set to be added in C++26 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3552r0.pdf.
Thus we need to rely on a library that provides those types or wait forever until C++ stdlib gets enough support. A non-exhaustive list of them is (in the order of being well-supported):
- kj-async (this is what lix project landed on)
- Boost.Cobalt recently merged and available since 1.87. Has avenues to integrate with ASIO.
- libcoro
- cppcoro - abandonware, just adding this for completeness sake.
Alternative solutions
Continue writing ad-hoc solutions and fix performance issues with threading.
Additional context
Checklist
- checked latest Nix manual (source)
- checked open feature issues and pull requests for possible duplicates
Add 👍 to issues you find important.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status