Skip to content

Commit a8de3f0

Browse files
hikejsclaude
andcommitted
perf(devices): add inline hints to hot-path helper functions
Add #[inline] attributes to small, frequently-called helper functions in virtio device hot paths: 1. vsock_windows.rs: - hdr_u16/u32/u64: Read header fields (called on every packet) - set_u16/u32/u64: Write header fields (called on every response) 2. net_windows.rs: - VirtioNetHdr::from_bytes: Parse header (called on every TX frame) - VirtioNetHdr::to_bytes: Serialize header (called on every RX frame) These functions are 1-3 lines and called in tight loops. Inlining eliminates function call overhead and enables better optimization. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e75e77b commit a8de3f0

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/devices/src/virtio/net_windows.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct VirtioNetHdr {
7373
}
7474

7575
impl VirtioNetHdr {
76+
#[inline]
7677
fn from_bytes(bytes: &[u8]) -> Self {
7778
if bytes.len() < VIRTIO_NET_HDR_SIZE {
7879
return Self::default();
@@ -87,6 +88,7 @@ impl VirtioNetHdr {
8788
}
8889
}
8990

91+
#[inline]
9092
fn to_bytes(&self) -> [u8; VIRTIO_NET_HDR_SIZE] {
9193
let mut bytes = [0u8; VIRTIO_NET_HDR_SIZE];
9294
bytes[0] = self.flags;

src/devices/src/virtio/vsock_windows.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,26 +333,32 @@ impl Vsock {
333333
mem.write_slice(hdr, addr).is_ok()
334334
}
335335

336+
#[inline]
336337
fn hdr_u16(hdr: &[u8; 44], off: usize) -> u16 {
337338
byte_order::read_le_u16(&hdr[off..off + 2])
338339
}
339340

341+
#[inline]
340342
fn hdr_u32(hdr: &[u8; 44], off: usize) -> u32 {
341343
byte_order::read_le_u32(&hdr[off..off + 4])
342344
}
343345

346+
#[inline]
344347
fn hdr_u64(hdr: &[u8; 44], off: usize) -> u64 {
345348
byte_order::read_le_u64(&hdr[off..off + 8])
346349
}
347350

351+
#[inline]
348352
fn set_u16(hdr: &mut [u8; 44], off: usize, value: u16) {
349353
byte_order::write_le_u16(&mut hdr[off..off + 2], value)
350354
}
351355

356+
#[inline]
352357
fn set_u32(hdr: &mut [u8; 44], off: usize, value: u32) {
353358
byte_order::write_le_u32(&mut hdr[off..off + 4], value)
354359
}
355360

361+
#[inline]
356362
fn set_u64(hdr: &mut [u8; 44], off: usize, value: u64) {
357363
byte_order::write_le_u64(&mut hdr[off..off + 8], value)
358364
}

0 commit comments

Comments
 (0)