lightbend-labs / jardiff

A tool for comparing JAR files, including method bodies and Scala 2 pickled signatures
Apache License 2.0
170 stars 23 forks source link

Add Scala 2 optimizer/inliner #169

Closed mdedetrich closed 7 months ago

mdedetrich commented 7 months ago

This PR enables the Scala2 optimizer to squeeze out some extra free performance. Since the project has both a core part and a cli part the optimizer is enabled differently for each

core: As the core is published as part of ci-release, the optimizer is only enabled in CI (i.e. github actions). It also uses "-opt-inline-from:<sources>" which is the most conservative option designed for libraries (i.e. it only optimizes the sources within each sbt module individually) cli: Since the cli is designed to be distributed as an application/executable (i.e. we create a fatjar via sbt-assembly) we can take advantage of this and do global optimization. There are 2 types of global optimization, one is optimizing everything including the JDK and the other is optimizing everything aside from the JDK (i.e. inside the scala.tools.jardiff package). I opted to go for the scala.tools.jardiff package because we are also distributing the fatjar generally as an artifact in github so we can't control what JDK the user runs on. Note that while it may seem like the difference between <sources> and scala.tools.jardiff is negligible now it will matter more when more sbt modules made (i.e. an additional one aside from core) since it globally inlines everything form that package (which as a fatjar is generally safe).

som-snytt commented 7 months ago

I wish I had backported the improved optimi(s/z)er options. IIRC there was only a bit of tweaking for options to parse it correctly.

The new syntax is just -opt:inline:<sources> for inlining power and -opt:local for minimum strength safety.