To reduce compile times of my project, I\'m caching certain type classes that are resolved by implicit lookups. This appears somewhat cumbersome though, because the straight for
Shapeless provides a cachedImplicit macro with an implementation that's very similar to yours (it uses shadowing to avoid the recursion, and the fact that it's a macro means the usage can be cleaner).
There are some limitations to be aware of, and you may not want to take on a new dependency for this single method, but the implementation is pretty concise, and it's at least a good starting point.