oxidecomputer / async-bb8-diesel

Safe asynchronous access to Diesel and the bb8 connection manager
MIT License
12 stars 8 forks source link

Use trait objects internally to avoid generic instantiation #60

Closed smklein closed 10 months ago

smklein commented 10 months ago

Keep the external interface to async transactions mostly unchanged, but delegate to internal functions that (as much as possible) avoid using generic functions.

This is intended to reduce code generation. For a debug build of omicron-nexus, this reduces the (debug build, Linux) binary size from 514 MiB to 497 MiB.

Source for idea: https://matklad.github.io/2021/09/04/fast-rust-builds.html#Keeping-Instantiations-In-Check

A... common case here are closures: by default, prefer &dyn Fn() over impl Fn(). Similarly to paths, an impl-based nice API might be a thin wrapper around dyn-based implementation which does the bulk of the work.