From f8e340ca1724515bd428753d94c200361bdec7c2 Mon Sep 17 00:00:00 2001 From: Razvan Dimescu Date: Wed, 25 Mar 2026 06:14:00 +0200 Subject: [PATCH] chore: simplify benchmark code after review - Remove redundant DnsHeader::new() (already set by DnsPacket::new()) - Remove unused DnsHeader import - Change simulate_cached_pipeline to take &DnsCache (lookup is &self now) - Remove unnecessary mut on cache in cache_lookup_miss bench Co-Authored-By: Claude Opus 4.6 (1M context) --- benches/hot_path.rs | 5 ++--- benches/throughput.rs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/benches/hot_path.rs b/benches/hot_path.rs index ecd84ae..accfcf2 100644 --- a/benches/hot_path.rs +++ b/benches/hot_path.rs @@ -3,14 +3,13 @@ use std::net::Ipv4Addr; use numa::buffer::BytePacketBuffer; use numa::cache::DnsCache; -use numa::header::{DnsHeader, ResultCode}; +use numa::header::ResultCode; use numa::packet::DnsPacket; use numa::question::{DnsQuestion, QueryType}; use numa::record::DnsRecord; fn make_response(domain: &str) -> DnsPacket { let mut pkt = DnsPacket::new(); - pkt.header = DnsHeader::new(); pkt.header.id = 0x1234; pkt.header.response = true; pkt.header.recursion_desired = true; @@ -93,7 +92,7 @@ fn bench_cache_lookup_hit(c: &mut Criterion) { } fn bench_cache_lookup_miss(c: &mut Criterion) { - let mut cache = DnsCache::new(10_000, 60, 86400); + let cache = DnsCache::new(10_000, 60, 86400); c.bench_function("cache_lookup_miss", |b| { b.iter(|| cache.lookup(black_box("nonexistent.com"), QueryType::A)) diff --git a/benches/throughput.rs b/benches/throughput.rs index 688b4e0..e01a25c 100644 --- a/benches/throughput.rs +++ b/benches/throughput.rs @@ -37,7 +37,7 @@ fn make_response(domain: &str) -> DnsPacket { /// Simulates the complete cached query pipeline (sans network I/O): /// parse → cache lookup → TTL adjust → serialize response -fn simulate_cached_pipeline(query_wire: &[u8], cache: &mut numa::cache::DnsCache) -> usize { +fn simulate_cached_pipeline(query_wire: &[u8], cache: &numa::cache::DnsCache) -> usize { let mut buf = BytePacketBuffer::from_bytes(query_wire); let query = DnsPacket::from_buffer(&mut buf).unwrap(); let q = &query.questions[0]; @@ -71,7 +71,7 @@ fn bench_pipeline_throughput(c: &mut Criterion) { b.iter(|| { for _ in 0..count { let wire = &query_wires[idx % query_wires.len()]; - simulate_cached_pipeline(wire, &mut cache); + simulate_cached_pipeline(wire, &cache); idx += 1; } });