Replacing Protobuf with Rust to go 5 times faster
CRANK

Jan 22nd, 2026Lev KokotovPgDog is a proxy for scaling PostgreSQL. Under the hood, we use libpg_query to parse and understand SQL queries. Since PgDog is written in Rust, we use its Rust bindings to interface with the core C library. Those bindings use Protobuf (de)serialization to work uniformly across different programming languages, e.g., the popular Ruby pg_query gem.Protobuf is fast, but not using Protobuf is faster. We forked pg_query.rs and replaced Protobuf with direct C-to-Rust (and back to C) bindings, using bindgen and Claude-generated wrappers. This resulted in a 5x improvement in parsing queries, and a 10x improvement in deparsing (Postgres AST to SQL string conversion).ResultsYou can reproduce these by cloning our fork and running the benchmark tests:FunctionQueries per secondpg_query::parse (Protobuf)613pg_query::parse_raw (Direct C to Rust)3357 (5.45x faster)pg_query::deparse (Protobuf)759pg_query::deparse_raw (Direct Rust to C)7319 (9.64x faster)The processThe first st…

pgdog.dev
Related Topics: Rust