Skip to content
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

Refactor Piece to use bytes crate #2559

Open
nazar-pc opened this issue Feb 26, 2024 · 0 comments
Open

Refactor Piece to use bytes crate #2559

nazar-pc opened this issue Feb 26, 2024 · 0 comments
Labels
good first issue Good for newcomers nice-to-have Non-critical but nice to have performance Related to performance measurement or improvement refactor

Comments

@nazar-pc
Copy link
Member

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) and PieceMut(BytesMut) instead, as well as changing FlatPieces(Vec<PieceArray>) to FlatPieces(Bytes).

A few examples where this will be helpful:

  • every time owned piece is more convenient to work with we can cheaply clone Piece without resorting to Arc<Piece>
  • in RPC layer where we store segment of archived history, Piece can actually refer to the same memory as the segment itself, avoiding additional allocations when sending pieces via RPC
@nazar-pc nazar-pc added good first issue Good for newcomers refactor performance Related to performance measurement or improvement nice-to-have Non-critical but nice to have labels Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers nice-to-have Non-critical but nice to have performance Related to performance measurement or improvement refactor
Projects
Development

No branches or pull requests

1 participant