Rust 解码 Protobuf 数据比 Go 慢五倍?记一次性能调优之旅
我们在优化 GreptimeDB v0.7 的写入性能时,通过火焰图发现耗费在解析 Prometheus write request 上的 CPU 时间片占了 12% 左右。相比之下,Go 语言开发的 VictoriaMetrics 耗费在协议解析上的 CPU 仅 5% 左右。这让我们不得不开始考虑优化协议转换层的开销。 为了简化行文,所有的测试代码存放在 GitHub 仓库中: https://github.com/v0y4g3r/prom-write-request-bench 优化步骤 Step1:复现 首先我们尝试使用一个最小可复现的 benchmark 来确认此问题。 对应分支: git checkout step1/reproduce Rust 相关性能测试代码(benches/prom_decode.rs): fn bench_decode_prom_request(c: &mut Criterion) { let mut d = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); d.push("asset...