Hello, in the past six months, I have implemented a shapeless-like library that solves another problem(like auto mapping between slick’s table and model).
Now I’ve finished 90% but no documentation and not tested.
When I was trying to implement a circe case class encoder, I found that my implementation performance was better than the official one.
In the use case of upickle’s self performance test(Test02.scala), asuna-circe uses circe’s api to show almost the same performance as upickle. In the use case of simple case class, asuna-circe is more faster than raw circe and upickle.
The principle is simple: force the user to define the encoder using valEncoder(strict or lazy) and defEncoder(non-strict). In valEncoder, use lazy value(need to support circular dependencies) to cache encoders in every field.
This implementation only uses about 150 line by only defining implicit base on asuna. And it’s easy to support snake-name and default value by asuna’s build-in API.
On top of this, we can redefine the field names, encoders, or both.
The above example also shows how to cache ‘non type parameter’ field’s encoders when the case class has type parameters.