perf: optimize hot path — RwLock, inline filtering, pre-allocated strings

- Mutex → RwLock for cache, blocklist, and overrides (concurrent read access)
- Make cache.lookup() and overrides.lookup() take &self (read-only)
- Eliminate 3 Vec allocations per DnsPacket::write() via inline filtering
- Pre-allocate domain strings with capacity 64 in parse path
- Add criterion micro-benchmarks (hot_path + throughput)
- Add bench README documenting both benchmark suites

Measured improvement: ~14% faster parsing, ~9% pipeline throughput,
round-trip cached 733ns → 698ns (~2.3M queries/sec).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Razvan Dimescu
2026-03-24 22:51:34 +02:00
parent 5d454cbed5
commit aed0e095e1
13 changed files with 729 additions and 77 deletions

View File

@@ -1,4 +1,4 @@
.PHONY: all build lint fmt check audit test clean deploy
.PHONY: all build lint fmt check audit test bench clean deploy blog
all: lint build
@@ -19,6 +19,17 @@ audit:
test:
cargo test
bench:
cargo bench
blog:
@mkdir -p site/blog
@for f in blog/*.md; do \
name=$$(basename "$$f" .md); \
pandoc "$$f" --template=site/blog-template.html -o "site/blog/$$name.html"; \
echo " $$f → site/blog/$$name.html"; \
done
clean:
cargo clean