Experiment with newtypes and scala-newtype
- Dominant language
- Scala
- Stars
- 1.7k
- Forks
- 152
- Avg merge
- 1h 20m
- Merged PRs (30d)
- 6
Description
[RefineJavapSpec.scala](https://github.com/fthomas/refined/blob/9358f95c8113fce711c32fb2b03e222a18de8982/modules/scalaz/jvm/src/test/scala-2.12/eu/timepit/refined/scalaz/RefineJavapSpec.scala) shows the boxing behavior and runtime overhead of the different refinement carrier that refined supports which are currently `Refined`, `shapeless.tag.@@`, and `scalaz.@@` (via the refined-scalaz module).
For reference types, all three carrier types do not box but using `Refined` causes an additional function call. For value types only `shapeless.@@` does not seem to box but causes two additional function calls. While the runtime overhead of `shapeless.tag.@@` and `scalaz.@@` is lower than for `Refined`, the latter is less susceptible to compiler bugs and quirks like:
* #21 (aka https://github.com/scala/bug/issues/8740) (`shapeless.tag.@@` does not work with aliases)
* https://github.com/circe/circe/issues/220, https://github.com/alexarchambault/argonaut-shapeless/issues/31, https://github.com/circe/circe/issues/784 (generic derivation with `shapeless.tag.@@` and `scalaz.@@` does not work reliably)
We should experiment if @alexknvl's https://github.com/alexknvl/newtypes or @carymrobbins https://github.com/estatico/scala-newtype could provide a viable replacement for `Refined` with lower (or zero) runtime overhead.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.