Skip to content

Import cats.syntax.all instead of cats.implicits in the kernel - #4711

Open
martijnhoekstra wants to merge 1 commit into
typelevel:series/3.xfrom
martijnhoekstra:kernel-syntax-imports
Open

martijnhoekstra wants to merge 1 commit into
typelevel:series/3.xfrom
martijnhoekstra:kernel-syntax-imports

Conversation

@martijnhoekstra

Copy link
Copy Markdown

Async and GenSpawnInstances import cats.implicits._. Loading that object runs the initializer of all of cats' standard instances, including the ones for BigDecimal and BigInt. On Scala Native the linker then keeps java.math and its dependencies in any program that uses Async's default async/async_/asyncCheckAttempt, including the libc imports strtod, strtof, log and log10.

This imports cats.syntax.all._ instead; the instances these files use come from implicit scope. GenSpawnInstances named catsStdInstancesForEither directly, which only the import brought in, so it now asks for Align[Either[E, *]].

Measured on Scala Native 0.5 (Linux x86-64, release-fast, stripped), with a minimal program that calls Async[F].async_ once on a small single-threaded Async instance. The two builds differ only in this import in Async.scala:

cats.implicits._ cats.syntax.all._
binary size 2,721,032 2,289,768 (−15.8%)
java.math symbols 182 2
cats.instances symbols 138 0
libc imports among strtod, strtof, log, log10 all four none

In a larger freestanding Scala Native program (a TCP echo server on its own effect runtime), the same change took the image from 3,036,296 to 2,484,336 bytes and removed its only references to those four libc functions.

Behaviour is the same. +kernelJVM/compile, +kernelNative/compile and +lawsJVM/test (1,618 tests on 2.12, 2.13 and 3) pass. The change adds and removes no API, so it could also go to series/3.7.x if you'd like it in a patch release.

Async and GenSpawnInstances imported cats.implicits._, whose initializer
builds cats' standard instances. On Scala Native that makes BigDecimal
and BigInt reachable from any program that uses Async's default async,
which links java.math and imports strtod, strtof, log and log10. The
syntax is all these files need; instances come from implicit scope.
@reardonj

reardonj commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@lolgab , tagging you for interest.

@martijnhoekstra
martijnhoekstra marked this pull request as ready for review November 5, 2026 23:08

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants