Derive typeclasses via Coercible hurts compiler performance?
See original GitHub issueSince the introduction of newtypes in conjuction with refined I see a big increase in compilation time. Especially in my postgres module. I was using refined before in my postgres module, but not with newtypes. I’m using doobie and SQL/fragment interpolated strings to construct queries. The string interpolator of doobie summons foreach interpolated variable a Put
type class (which is used to convert the variable being interpolated to a JDBC data type).
Here’s the code to convert newtypes to Put
and Get
(for reading data from JDBC)
implicit def coerciblePut[N, P](implicit ev: Coercible[Put[P], Put[N]], R: Put[P]): Put[N] = ev(R)
implicit def coercibleGet[N, P](implicit ev: Coercible[Get[P], Get[N]], R: Get[P]): Get[N] = ev(R)
I’ve included the scalac-profiling aswell: https://gist.github.com/Fristi/363e7fcf8f899e24eae53d42d741fd13
It seems to not have repeeated expansions, but rather unique expansions
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Strategic Deriving - Kowainik
What are deriving strategies and how do you get a habit of using them ... A compiler is a data type, and the...
Read more >Deriving strategies - Type Classes
via : With the DerivingVia extension enabled, this strategy produces instances that behave the same as those of some other specified type, as...
Read more >Type Class Derivation in Scala 3 - Medium
This has advantages over reflection, like type safety and performance. As macros are low level and complicated, there are two main libraries in ......
Read more >Glasgow Haskell Compiler 8.6.3 User's Guide
DerivingVia, Enable deriving instances via types of the same runtime ... HasField is a magic built-in typeclass (similar to Coercible, for example).
Read more >Deriving type classes in Haskell is slow - Taylor Fausak
Since I'm focusing on deriving type classes, it made sense to have a lot of different data types. Rather than come up with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Idk it’s hard to tell without looking at the codebase. But perhaps eliminating implicit searches like these:
In Haskell you should probably prefer
StandaloneDeriving
withGeneralizedNewtypeDeriving
Yes, it can be boilerplatey if you have a lot of them, but it’s a bit safer this way. It might not always be the case that you wanted an instance for some particular newtype, or even that instance. Always better to define them explicitly. So in Scala, I recommend a similar strategy for the same reasons.
Fantastic!