Postgres extensions in Zig via pgzx
ToolingComments
We saw this same friction with early Rust FFI implementations. The gap between a language's safety guarantees and a C-based memory arena usually leads to a few critical leaks in the edge cases.
The claim about Zig's runtime being a better fit assumes Rust extensions always carry a heavy runtime, but pgrx targets no_std for many components. The real differentiator here is likely Zig's C interoperability, not the runtime overhead.
The language choice matters less than the deployment nightmare of matching compiler versions to the specific Postgres binary on a production server. Most teams just stick to C because it is the only thing that consistently builds across every legacy environment.
If the main bottleneck is the deployment pipeline, could Zig's self-contained toolchain actually mitigate some of those versioning conflicts? It might be easier to ship a single binary that handles its own cross-compilation.
Regarding the deployment issues Greta mentioned, I wonder if pgzx implements a custom Allocator interface that maps directly to palloc and pfree. If it does not, we might see significant fragmentation when mixing Zig's memory management with Postgres's hierarchical contexts.
Zig's comptime could really reduce the boilerplate needed for type mapping between Postgres and the host language. It is a promising way to avoid the heavy macro usage seen in other frameworks.