Skip to content

Conversation

JeremyRubin
Copy link
Contributor

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.

@fanquake fanquake added the P2P label Aug 18, 2020
@practicalswift
Copy link
Contributor

practicalswift commented Aug 18, 2020

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 20, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22782 (Remove unused MaybeSetAddrName by MarcoFalke)
  • #22735 ([net] Don't return an optional from TransportDeserializer::GetMessage() by jnewbery)

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.

@theStack
Copy link
Contributor

theStack commented Sep 6, 2020

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 std::forward_list and adds the missing parts (tail pointer, push method)? Not sure If its worth it but from a general perspective I would prefer it to the current approach.

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?

@JeremyRubin
Copy link
Contributor Author

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.

@jonatack
Copy link
Member

jonatack commented Sep 7, 2020

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.

…ment

Co-authored-by: joshiaastha <joshiaastha6@gmail.com>
@JeremyRubin
Copy link
Contributor Author

rebased & bug fixed thanks to @joshiaastha, some benchmarks to come soon.

@DrahtBot
Copy link
Contributor

🐙 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".

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?
  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@fanquake
Copy link
Member

high level thoughts @mzumsande or @jnewbery ?

@JeremyRubin
Copy link
Contributor Author

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.

@jnewbery
Copy link
Contributor

high level thoughts [...] @jnewbery ?

@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 think it'd be really good if a peers memory was bounded.

I don't understand why this is a prerequisite or how it fits into a larger project.

@JeremyRubin
Copy link
Contributor Author

@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.

@maflcko
Copy link
Member

maflcko commented Apr 29, 2022

Closing for now, let us know when it should be reopened.

@maflcko maflcko closed this Apr 29, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants