Skip to main content
Version: 2.x

Compiler performance

Quill will probably make the slow scala compiler even slower, since a lot of additional Parsing, Typechecking, Implicit resolution works introduced to expand a Query.

Following tips may help improving compilation time.

Use -Yprofile-trace scalac options.โ€‹

With -Yprofile-trace option, a chrome trace file will be produced after compilation. It will help figure out what slowing down the compiler.

Note, this option need some tweak if you are running on java 9 or newer version.

Split large module into multiple submodulesโ€‹

Since scalac is not fully parallelized, split into independent submodules can significantly reduce build time on multi-core cpu.

Define decoder/encoder directly instead of MappedEncodingโ€‹

MappedEncoding introduce more implicit resolutions, which may slow down compiler.

It is possible to define instance directly.

case class FooId(id: Long)
implicit val fooIdEncoder: Encoder[FooId] = mappedEncoder(MappedEncoding[FooId, Long](_.id), longEncoder)
implicit val fooIdDecoder: Decoder[FooId] = mappedDecoder(MappedEncoding[Long, FooId](FooId(_)), longDecoder)

Share QueryMeta instanceโ€‹

QueryMeta generation requires Decoder resolution, tree generation, typechecking, etc which can be very slow.

QueryMeta is not shared by default, so define shared QueryMeta instance may reduce build time.

val ctx = SqlMirrorContext(MirrorIdiom, Literal)

// Prevent using default macro generated query meta instance.
// Use `_` instead of `*` if `-Xsource:3` not enabled.
import ctx.{ materializeQueryMeta => *, * }

// Instance type must not be specified here, otherwise it will become dynamic query.
implicit val orderQueryMeta = ctx.materializeQueryMeta[Order]

ctx.run {
query[Order]
}

Note, to use -Xsource:3 scalac options, -Xmigration or -Wconf:cat=scala3-migration:w is required.

Otherwise, it will not compile due to lack of explicit type of implicit definition.

ZIO Chat

๐ŸŽ‰ Hey there, ZIO aficionado! ๐ŸŽ‰ Step into the ZIO wonderland with me as your guide. Whether you're a functional fanatic or just dipping your toes into the ZIO ecosystem, I'm here to make your journey smooth. Got ZIO questions? I've got answers! Let's navigate the ZIO universe together and unlock its infinite possibilities!