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

reduce memory copying in tpu-client-next #4682

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions tpu-client-next/src/transaction_batch.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
//! This module holds [`TransactionBatch`] structure.

use solana_time_utils::timestamp;
use {solana_time_utils::timestamp, tokio_util::bytes::Bytes};

/// Batch of generated transactions timestamp is used to discard batches which
/// are too old to have valid blockhash.
#[derive(Clone, PartialEq)]
pub struct TransactionBatch {
wired_transactions: Vec<WiredTransaction>,
// Time of creation of this batch, used for batch timeouts
timestamp: u64,
}

type WiredTransaction = Vec<u8>;
type WiredTransaction = Bytes;

impl IntoIterator for TransactionBatch {
type Item = Vec<u8>;
type Item = Bytes;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.wired_transactions.into_iter()
}
}

impl TransactionBatch {
pub fn new(wired_transactions: Vec<WiredTransaction>) -> Self {
pub fn new<T>(wired_transactions: Vec<T>) -> Self
where
T: AsRef<[u8]> + Send + 'static,
{
let txs = wired_transactions
.into_iter()
.map(|v| Bytes::from_owner(v))
.collect();
alexpyattaev marked this conversation as resolved.
Show resolved Hide resolved

Self {
wired_transactions,
wired_transactions: txs,
alexpyattaev marked this conversation as resolved.
Show resolved Hide resolved
timestamp: timestamp(),
}
}
Expand Down
Loading