amnaredo / test

0 stars 0 forks source link

Derivation for seqish types should short-circuit before recursing on `W[T]` #162

Open amnaredo opened 2 years ago

amnaredo commented 2 years ago

SeqishW in Implicits.scala with signature

implicit def SeqishW[T: W, V[_] <: Iterable[_]]: W[V[T]] = W[V[T]]

can cause a needlessly long increase in compilation time. It first triggers a search for W[T], even if it might not apply.

A fix was published by @patrick-premont and can be seen in his fork of upickle. We use a similar fix to save ~600s compilation time in our code base. There are other workarounds (you can generate your own Writers or extend AttributeTagged with some of your own implicits to avoid forking), but it'd be nice to be able to use the standard automatic typeclass derivation packed with upickle.

Background:

We're using slick with a large database and generate case classes for each row. We cross-compile these js and jvm and then use upickle to serialize these case classes.

We also have a typed ID, like so: case class ID[SomeDataBaseRow](id: Int). The serialization of an Id is simple and doesn't need to recurse on SomeDataBaseRow, because you only need a Writer[Int]. When upickle tries to recurse, it essentially ends up deriving Writers for every table type in the database.

ID: 137 Original Author: stewSquared

amnaredo commented 2 years ago

Fixed by #138

Original Author: lihaoyi