perf(fake-tcp) let the memory allocator zero initialize the BytesMut memory instead of resizing immediately after allocation

Co-authored-by: Datong Sun <dndx@idndx.com>
This commit is contained in:
Paolo Barbolini 2022-08-19 04:00:09 +02:00 committed by GitHub
parent f374ac8081
commit 6af7757456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 4 deletions

View File

@ -436,8 +436,7 @@ impl Stack {
let mut tuples: HashMap<AddrTuple, flume::Sender<Bytes>> = HashMap::new();
loop {
let mut buf = BytesMut::with_capacity(MAX_PACKET_LEN);
buf.resize(MAX_PACKET_LEN, 0);
let mut buf = BytesMut::zeroed(MAX_PACKET_LEN);
tokio::select! {
size = tun.recv(&mut buf) => {

View File

@ -47,8 +47,7 @@ pub fn build_tcp_packet(
let tcp_header_len = TCP_HEADER_LEN + if wscale { 4 } else { 0 }; // nop + wscale
let tcp_total_len = tcp_header_len + payload.map_or(0, |payload| payload.len());
let total_len = ip_header_len + tcp_total_len;
let mut buf = BytesMut::with_capacity(total_len);
buf.resize(total_len, 0);
let mut buf = BytesMut::zeroed(total_len);
let mut ip_buf = buf.split_to(ip_header_len);
let mut tcp_buf = buf.split_to(tcp_total_len);