Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with newtypes and scala-newtype #465

Open
fthomas opened this issue Apr 5, 2018 · 2 comments
Open

Experiment with newtypes and scala-newtype #465

fthomas opened this issue Apr 5, 2018 · 2 comments

Comments

@fthomas
Copy link
Owner

fthomas commented Apr 5, 2018

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:

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.

@carymrobbins
Copy link

@fthomas FWIW, I recently added @newsubtype macro support, which gets us unboxed primitives -

estatico/scala-newtype#14

I plan on cutting a release including this feature in the near future. If folks are wanting this sooner rather than later I can prioritize as need be.

@fthomas
Copy link
Owner Author

fthomas commented Apr 6, 2018

@carymrobbins Unboxed primitives sounds great and the subtyping relation fits well for refinement types. I'll will definitely try that for refined. There is no hurry to cut a release from my side, It'll take a me little while before I can do these experiments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants