-
Notifications
You must be signed in to change notification settings - Fork 37.7k
net/net_processing: Convert net std::list buffers to std::forward_list #19757
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
Conversation
Personally I find it easier to reason about the correctness of the existing version, and I'm not entirely convinced that the benefit (slight memory saving) justifies the cost (+23 −9) in this case. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Interesting idea! I tend to agree with @practicalswift though that probably the memory saving benefit doesn't outweigh the reduced code readability, at least not in the current form when the user part of the data structure suddenly has to take care of maintaining additional internal state that should not be exposed. Would it be possible to generalize the concept by creating a new container that inherits from Another question, from the perspective of an STL noob: If we want to store a message queue, why we didn't simply choose std::queue? Is it because of the .splice() magic that wouldn't be possible then? |
Yeah it would be possible to encapsulate the API to a generic container. It may be worth doing this IMO because we can replace malloc with a bounded free-list or a circular buffer or something else that can perform a lot better without worrying about the underlying structures. But for STL magic, yes splicing a list is a bit special so something else would have trouble replicating that. |
I think this is interesting. Builds cleanly but lot of the functional tests are failing for me locally. Happy to re-review if they are fixed. |
313ca5c
to
4a3e45f
Compare
…ment Co-authored-by: joshiaastha <joshiaastha6@gmail.com>
4a3e45f
to
31603fe
Compare
rebased & bug fixed thanks to @joshiaastha, some benchmarks to come soon. |
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
high level thoughts @mzumsande or @jnewbery ? |
i can rebase it if interest -- @joshiaastha was working on some USDT based measures for latency and similar, but I think got stuck before SoB ended. longer run i'd like for these to be circular buffers with overflow either freezing the net thread or going into a list. I think it'd be really good if a peers memory was bounded. |
@fanquake no strong opinion. Saving 8 bytes per network message is extremely low priority for me, but I won't stand in the way if other people think it's worth it.
I don't understand why this is a prerequisite or how it fits into a larger project. |
@theStack's feedback was to ask if we can encapsulate this messier API, and I said sure, that would also be good towards a longer term more difficult project to implement a circular buffer. |
Closing for now, let us know when it should be reopened. |
Currently we use a std::list for the message queue. This is a doubly-linked list. However, we never insert things in the middle, we only really pull from the front or append to the back. Thus we can replace std::list with std::forward_list, which saves a bit of memory per message (8 bytes, plus having to set the back pointers).
Not the highest priority PR, but a decent refactor I spotted while looking at this code for an unrelated reason that doesn't add that much code complexity. Shakes fist at STL for not making std::forward_list store a tail pointer, but it's easy enough to implement on your own.