Refactor Piece to use bytes crate #2559
Labels
good first issue
Good for newcomers
nice-to-have
Non-critical but nice to have
performance
Related to performance measurement or improvement
refactor
There are a few places related to pieces that can be much more efficient and convenient to use than they currently are.
Right now we have
Piece(Box<PieceArray>)
, which means additional allocation every time we need a new piece instance.This can be greatly optimized using https://docs.rs/bytes by having
Piece(Bytes)
andPieceMut(BytesMut)
instead, as well as changingFlatPieces(Vec<PieceArray>)
toFlatPieces(Bytes)
.A few examples where this will be helpful:
Piece
without resorting toArc<Piece>
Piece
can actually refer to the same memory as the segment itself, avoiding additional allocations when sending pieces via RPCThe text was updated successfully, but these errors were encountered: