Parent Issue
Part of #315 (TCP receive std::span callback migration)
Summary
Add a focused benchmark that quantifies the overhead difference between:
- span-based receive dispatch (no per-iteration allocation)
- legacy vector-based receive dispatch (per-iteration allocation + copy)
This provides a concrete baseline for the TCP receive hot-path migration and helps detect regressions in CI.
Background
After #316, tcp_socket can deliver received bytes as std::span<const uint8_t> without allocating/copying into a temporary vector. We should add a micro benchmark to validate the expected performance gap and keep it visible over time.
Proposed Benchmarks
Add a new benchmark file (or extend an existing one):
benchmarks/tcp_receive_bench.cpp (preferred) or extend benchmarks/message_throughput_bench.cpp
Benchmarks:
-
BM_TcpReceive_Dispatch_Span
- Create a fixed
std::array<uint8_t, N>
- Create a
std::span<const uint8_t> view
- Invoke a trivial callback that touches bytes (to prevent dead-code elimination)
- No vector construction
-
BM_TcpReceive_Dispatch_VectorFallback
- Same fixed input
- Construct
std::vector<uint8_t> each iteration (simulating legacy adapter path)
- Invoke the same callback signature
Optional:
- Run with
--benchmark_min_time=5.0 for stable results in CI.
Files to Update
benchmarks/CMakeLists.txt
- Add
benchmarks/tcp_receive_bench.cpp (or modify existing benchmark sources)
Acceptance Criteria
Test Plan
Local:
cmake -B build -S . -DNETWORK_BUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/benchmarks/network_benchmarks --benchmark_filter=TcpReceive --benchmark_min_time=3.0
Notes
This benchmark intentionally isolates dispatch/copy costs; it does not attempt to benchmark kernel/network I/O.
Parent Issue
Part of #315 (TCP receive std::span callback migration)
Summary
Add a focused benchmark that quantifies the overhead difference between:
This provides a concrete baseline for the TCP receive hot-path migration and helps detect regressions in CI.
Background
After #316,
tcp_socketcan deliver received bytes asstd::span<const uint8_t>without allocating/copying into a temporary vector. We should add a micro benchmark to validate the expected performance gap and keep it visible over time.Proposed Benchmarks
Add a new benchmark file (or extend an existing one):
benchmarks/tcp_receive_bench.cpp(preferred) or extendbenchmarks/message_throughput_bench.cppBenchmarks:
BM_TcpReceive_Dispatch_Spanstd::array<uint8_t, N>std::span<const uint8_t>viewBM_TcpReceive_Dispatch_VectorFallbackstd::vector<uint8_t>each iteration (simulating legacy adapter path)Optional:
--benchmark_min_time=5.0for stable results in CI.Files to Update
benchmarks/CMakeLists.txtbenchmarks/tcp_receive_bench.cpp(or modify existing benchmark sources)Acceptance Criteria
-DNETWORK_BUILD_BENCHMARKS=ONTest Plan
Local:
cmake -B build -S . -DNETWORK_BUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release cmake --build build ./build/benchmarks/network_benchmarks --benchmark_filter=TcpReceive --benchmark_min_time=3.0Notes
This benchmark intentionally isolates dispatch/copy costs; it does not attempt to benchmark kernel/network I/O.