SinkToSource: avoid heap allocation#12255
Conversation
|
@Mic92 Can you review and merge this PR, please? |
|
@edolstra you reviewed the commit yesterday in the meeting but didn't write a comment afterwards. |
|
Notes from the team meeting:
|
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2024-01-15-nix-team-meeting-minutes-208/58993/1 |
|
|
I did the move semantics approach in #12296. |
|
I'm not entirely convinced that we need a ring buffer here. Note that these are coroutines and not threads, so we have control over whether the producer or consumer is running for any given state. This means that we could instead implement a regime where
If a producer were to allocate large or arbitrary buffers, that could indeed be a problem, but that problem would need to be resolved in the producer anyway. I believe this is a more efficient solution within the current constraints. We'd have to reconsider if we were to use threads or an async I/O runtime that allows us to yield to arbitrary threads and resume the producer while the consumer is still processing. |
|
I changed the PR, so that additional heap allocations are avoided. Furthermore no unnecessary memory copy is done anymore. |
|
I dropped unrelated parentheses changes. |
Motivation
This PR refactors
SinkToSource, so that its instances don't allocate astd::stringand unnecessary memory copies are avoided, too.Context
The current implementation does not release the allocated
std::stringbefore theSinkToSourceobject is destroyed. This can cause unlimited usage, when the lifetime ofSinkToSourceobjects is longer than expected.Would have prevented #7359
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.