Skip to content

Commit

Permalink
packet: Use Bytes instead of an array in Packet
Browse files Browse the repository at this point in the history
The reason behind the switch is that `Packet` gets cloned in multiple
places. `Bytes` provides a zero-copy abstraction, where calling
`clone()` doesn't make an actual copy of the underlying data and all
instances point to the same memory.

However, the old layout containing a sized array is convenient for CUDA.
To not break CUDA support, this change introduces a new struct called
`PacketArray`, which a `Packet` can be converted into just before
calling GPU-based sigverify. That requires a copy, ideally just one.

At the same time, CPU-based sigverify and all the other components are
going to benefit from zero-copy properties of `Bytes`.
  • Loading branch information
vadorovsky committed Feb 20, 2025
1 parent 46b3ec1 commit 3eaa076
Show file tree
Hide file tree
Showing 4 changed files with 414 additions and 120 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ bs58 = { version = "0.5.1", default-features = false }
bv = "0.11.1"
bytemuck = "1.21.0"
bytemuck_derive = "1.8.1"
bytes = { version = "1.10", features = ["serde"] }
cfg_eval = "0.1.2"
chrono = { version = "0.4.39", default-features = false }
console = "0.15.10"
Expand Down
1 change: 1 addition & 0 deletions packet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = { workspace = true }
[dependencies]
bincode = { workspace = true, optional = true }
bitflags = { workspace = true }
bytes = { workspace = true }
cfg_eval = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
Expand Down
Loading

0 comments on commit 3eaa076

Please sign in to comment.