perf(shrex/client): reduce memory usage by removing the buffer - #5177
perf(shrex/client): reduce memory usage by removing the buffer#5177vgonkivs wants to merge 2 commits into
Conversation
|
Tick the box to add this pull request to the merge queue (same as
|
|
60a9855 to
6266bc1
Compare
6266bc1 to
bdf1b93
Compare
bdf1b93 to
068aaf6
Compare
renaynay
left a comment
There was a problem hiding this comment.
Do we really need countingReader ? I get that we want real bytes tx'd over the wire but we can get these metrics from libp2p bandwidth reporter (for the shrex-eds protocol) and even get per-peer metrics as well.
I won't die on the hill but 🤷🏻♀️
|
Good call. For this PR I'll keep countingReader bc it just preserves the existing per-request "bytes received" log/trace that the removed bytes.Buffer gave via buff.Len(), so no behaviour change. Wiring shrex-eds traffic to the libp2p bandwidth reporter (per-peer/per-protocol) and dropping countingReader is a self-contained metrics change, so I'd propose to do it in a follow-up pr |
renaynay
left a comment
There was a problem hiding this comment.
This solution will block libp2p stream til square is reconstructed + hashed.
Rather do something like this:
type edsResponse struct {
shares []libshare.Share
eds *eds.Rsmt2D
}
func (r *edsResponse) ReadFrom(src io.Reader) (int64, error) {
cr := &countingReader{r: src}
shares, err := eds.ReadShares(cr, libshare.ShareSize, r.odsSize)
if err != nil {
return cr.n, err
}
r.shares = shares
return cr.n, nil
}
leave reconstruction logic to build func that's also passed in to executeRequest
Good catch. Fixed |
renaynay
left a comment
There was a problem hiding this comment.
Ah sorry, last request hopefully last back and forth:
let's not read too much from the stream (1x per share read), you can wrap the stream in a smaller (like 64kib) buffered reader and read the shares from that instead. So there will be tiny allocation but better than reading from stream num_shares amount of times.
Pull request was converted to draft
|
Let me clarify smth:
My suggestion is to keep the solution as you proposed initailly w/o another buffer. Adn do buffering at the stream level when we will be implementing range-eds(we could have io.LimitReader per eds per stream) |
Resolves PROTOCO-2384
Reduce memory usage by removing an internal buffer. And stream the EDS directly.