Table of Contents

Wire 线编码基线

数字权威基线——快照非编年史;引用不复制。

环境

项 值
CPU / 内存 i5-12400 / 31.7 GB
OS / 运行时 Windows 11 专业版 26200 / .NET 8.0.422
框架 BenchmarkDotNet 0.14.0,Release,3 暖 15 测
采集日 2026-10-12

配置

  • 消息族两档载荷:Small ~64B(ulong+uint+byte[64])、Large ~1KB(ulong+byte[1024])。
  • EncodePooled = ArrayPool 租借 + 编码 + 归还(租借含在测)。

数字

场景 Mean 分配
Small Encode 新数组 19.61 ns 112 B
Small EncodePooled 21.85 ns 0 B
Small TryDecode 24.40 ns 112 B
Large Encode 新数组 141.0 ns 1,064 B
Large EncodePooled 32.26 ns 0 B
Large TryDecode 164.3 ns 1,064 B

现状选型建议

  • 热路径(管道直写/复用缓冲)用 EncodePooled——大载荷消掉 1KB/次分配(0 B 实测), 租借成本恒定 ≈ 32 ns 与载荷无关。
  • Encode 新数组形态适合一次性小消息(64B 档 19.6 ns,112 B 分配无碍)。

复现

dotnet run --project benchmarks/KernLab.Loom.Wire.Benchmarks -c Release -- --filter '*'