-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SinkToSource: avoid heap allocation #12255
base: master
Are you sure you want to change the base?
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 |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::string
and unnecessary memory copies are avoided, too.Context
The current implementation does not release the allocated
std::string
before theSinkToSource
object is destroyed. This can cause unlimited usage, when the lifetime ofSinkToSource
objects 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.