pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

Measuring PGRX overhead with a Rust vs C extension benchmark

Open mllorente-msft opened this issue 11 months ago • 1 comments

Hi all. As an exercise I rewrote an extension similar to pg_stats_statements where the extension counts the number of queries fired in a given time period. When benchmarking my Rust extension using PGRX against the extension written in C, I found about a ~10% decrease in total queries being fired, which to me indicates a slight overhead that PGRX had. Not sure if there is any similar discourse that exists on this topic, but just wanted to share my findings and see if anyone else has run a benchmark on comparing Rust and C extensions for postgres. On the discord, a couple users have discussed that the overhead can perhaps be attributed to SPI and variable types.

mllorente-msft avatar Jan 24 '25 20:01 mllorente-msft

Remove #[pg_guard] annotations and see what happens. I'm not recommending this for production -- pg_guard is pretty important for safety -- but it may account for the difference.

ccleve avatar Jan 27 '25 19:01 ccleve