-
Notifications
You must be signed in to change notification settings - Fork 957
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
feat(quick-protobuf-codec): reduce allocations during encoding #4782
Conversation
Draft because it is stacked on top of another PR, but ready for review. |
@thomaseizinger I'm trying to have a bash at this for heaptracking, but getting compile errors atm. Is there a stablish commit here worth testing from? eg |
Try the one before the last merge commit! Sorry for that, I didn't expect there to be compile errors with merging master 😅 |
Ran into issues today and didnt have time to get deeper. Probs will be next week when i come back with heaps i'm afraid as I'm off tomorrow |
Perhaps @jxs has time to check whether this reduces allocations for lighthouse? |
Hi @joshuef this seems fixable by running
Sorry Thomas, this fix runs on the latest |
Oh, thanks for trying @jxs. I might try and backport it for |
9dbeeda
to
7975a8b
Compare
7975a8b
to
81ef6cc
Compare
81ef6cc
to
7893b81
Compare
cc @altonen It might be of interest to you as maintainer of In our case, that would be a protobuf-aware codec. With the current impl (prior to this PR), we have to encode the message into a temporary buffer because the codec in This is quite significant as it affects every protobuf message sent over libp2p, e.g. kademlia, gossipsub, identify, ... |
Thanks for the ping. I've noticed the same thing as well which is why litep2p is not directly using If I ever find time, I'll take a look if the issue can be fixed in |
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.
As mentioned out-of-band, great catch!
This comment was marked as resolved.
This comment was marked as resolved.
… BufMut::put Builds on top of libp2p#4782. Removes the requirement for `unsafe` code.
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.
Thanks for the find and the fix!
@mergify refresh |
✅ Pull request refreshed |
Reran webrtc job. Seems like it didn't get a runner. |
Description
We can reduce the number of allocations during the encoding of messages by not depending on the
Encoder
implementation ofunsigned-varint
but doing the encoding ourselves.This allows us to directly plug the
BytesMut
into theWriter
and directly encode into the target buffer. Previously, we were allocating each message as an additional buffer that got immediately thrown-away again.Related: #4781.
Notes & open questions
Change checklist