cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
755 stars 31 forks source link

Optimising codegen using an asynchronous client and pipelining #215

Open Virgiel opened 1 year ago

Virgiel commented 1 year ago

When benchmarking codegen, I found that we spent most of our time communicating with the database synchronously to prepare each query one by one. By using an asynchronous client and relying on pipelining, codegen's time went from 22ms to 6ms on my machine.

Virgiel commented 1 year ago

When we generate code against a managed database, most of our time is spent on docker commands, 1.3s when managed vs 50ms when live. We don't have an easy way to improve this.

Parsing is also an expensive CPU task that we can parallelize by module, but the gain is less: 6ms down to 4ms. Finally, we could also use mmap instead of reading queries and schema files into memory for even smaller but easy gain.