Skip to content

Principled async operations for the store layer via C++20 stackless coroutines #14612

@xokdvium

Description

@xokdvium

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:

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


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposalperformancestoreIssues and pull requests concerning the Nix store

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions