Skip to content

Commit

Permalink
uses serde_bytes for (de)serializing Vec<u8> (#4088)
Browse files Browse the repository at this point in the history
By default Vec<u8> is treated just as any Vec<T> and is inefficiently
(de)serialized byte by byte.
serde_bytes instead uses Serializer::serialize_bytes and
Deserializer::deserialize_bytes which do so more efficiently.
https://docs.rs/serde/latest/serde/trait.Serializer.html#tymethod.serialize_bytes
https://docs.rs/serde/latest/serde/trait.Deserializer.html#tymethod.deserialize_bytes
  • Loading branch information
behzadnouri authored Dec 13, 2024
1 parent 73289ca commit f70d6b6
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion core/src/consensus/tower_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ impl From<SavedTower1_7_14> for SavedTowerVersions {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "2XiuhmDfRzWGdwZdMbpH5NcjGnTRi9zY1XTNHSknddA7")
frozen_abi(digest = "GqJW8vVvSkSZwTJE6x6MFFhi7kcU6mqst8PF7493h2hk")
)]
#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct SavedTower {
signature: Signature,
#[serde(with = "serde_bytes")]
data: Vec<u8>,
#[serde(skip)]
node_pubkey: Pubkey,
Expand Down
1 change: 1 addition & 0 deletions gossip/src/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ impl Default for CompressionType {
pub(crate) struct EpochIncompleteSlots {
first: Slot,
compression: CompressionType,
#[serde(with = "serde_bytes")]
compressed_list: Vec<u8>,
}
1 change: 1 addition & 0 deletions gossip/src/epoch_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl Sanitize for Uncompressed {
pub struct Flate2 {
pub first_slot: Slot,
pub num: usize,
#[serde(with = "serde_bytes")]
pub compressed: Vec<u8>,
}

Expand Down
1 change: 1 addition & 0 deletions ledger-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ num_cpus = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
solana-account-decoder = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions ledger-tool/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ pub struct CliDuplicateShred {
merkle_root: Option<Hash>,
chained_merkle_root: Option<Hash>,
last_in_slot: bool,
#[serde(with = "serde_bytes")]
payload: Vec<u8>,
}

Expand Down
1 change: 1 addition & 0 deletions ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct Account {
struct Input {
program_id: String,
accounts: Vec<Account>,
#[serde(with = "serde_bytes")]
instruction_data: Vec<u8>,
}
fn load_accounts(path: &Path) -> Result<Input> {
Expand Down

0 comments on commit f70d6b6

Please sign in to comment.