Skip to content

Conversation

@levkk
Copy link
Collaborator

@levkk levkk commented Dec 31, 2025

We forked pg_query and replaced protobuf (de)serialization with native C/Rust bindings.

This results in the following performance improvements:

  1. Query parsing is 5x faster.
  2. Query construction using the Posgres AST builder is 10x faster. We can generate queries on the fly with virtually no performance overhead.
  3. pg_bench is reporting a 25% improvement in benchmarks using the simple protocol, which we don't cache. This is great for clients that don't support or use prepared statements (e.g. Rails!).

This is configurable with the new query_parser_engine setting:

[general]
query_parser_engine = "pg_query_raw" # pg_query_protobuf to use the old protobuf-based path

While we continue to test this, we'll be using the old protobuf-based paths by default. This PR therefore won't affect any current deployments and adoption is completely optional.

Things we need to optimize:

  1. The raw C parser is very recursive. We're currently bumping up the Tokio worker stack size to 32MiB to make sure there is enough to parse complex statements, but that increases our memory requirements quite a bit. This is per thread, so if you have 4 threads, PgDog will allocate 32 x 4 = 132 MiB of stack memory on boot. For most modern systems that's not a problem, but still, the memory usage increases quite a bit.
  2. The parser may not be complete. While we test it extensively, the number of Postgres AST nodes is high.

Misc

Upgraded rand to 0.9.2.

@blacksmith-sh

This comment has been minimized.

@levkk levkk changed the title refactor: remove protobuf feat: query parser backend without protobuf in pg_query Jan 1, 2026
@blacksmith-sh

This comment has been minimized.

@blacksmith-sh

This comment has been minimized.

@levkk levkk merged commit 42df93f into main Jan 2, 2026
12 of 14 checks passed
@levkk levkk deleted the levkk-no-more-protobuf branch January 2, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants