semiotic-ai / timeline-aggregation-protocol

A fast, efficient and trust-minimized unidirectional micro-payments system.
Apache License 2.0
14 stars 3 forks source link

Suggestion: use trait objects instead of generics #134

Closed ozgrakkurt closed 9 months ago

ozgrakkurt commented 1 year ago

We could use trait objects instead of generics in manager, and maybe some other places.

This would make compilation faster and also remove clutter in places where we handle these types. The cost of dynamic dispatch should be negligible for sure.

Imo the tradeoff between performance and readability would be fine if we do this.

Compilation time gain might be minimal in this case since this library is relatively small. But I know this is good practice, because a lot of libraries like tokio, hyper, actix have very big compilation times because they use generics in every place possible. Also their APIs are hard to read since they use a lot of type features even though it isn't strictly needed. One big example is this library: warp which has insane compilation times if you don't explicitly make it use trait object with to_boxed kind of methods.

Also developer time spent waiting for compilation and time spent trying to understand code is important, I would recommend this talk about it.