Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
You also don't need to stick with one strategy for everything. You can treat this as an optimization problem, and choose how much to specialize for each parameter, perhaps based on how it's used. Swift goes so far as to build a fully polymorphic version of exported functions, then specialize them internally and based on opt-in annotations: https://gankra.github.io/blah/swift-abi/. There have also been attempts to approach this from the other direction in Rust, by detecting cases where a function doesn't make any use of a type's layout: https://github.com/rust-lang/rust/pull/69749
Also take a look at https://github.com/golang/proposal/blob/master/design/generics-implementation-gcshape.md. This is a hybrid approach (like the one you're talking about) the Go compiler takes for its generics implementation. It uses GC allocation size classes ("shapes") to figure out how to group types that need to be monomorphized.