This a pure practical story of me trying to profile Scala compilation time.
There is a great article about this topic: SPEEDING UP COMPILATION TIME WITH SCALAC-PROFILING
However, when I decided to try scalac-profiling out — I run into a lot of troubles like:
[error] java.lang.reflect.InvocationTargetException
[error] sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error] sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java: 62)
[error] sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java: 45)
[error] java.lang.reflect.Constructor.newInstance(Constructor.java: 423)
...
or
[error] bad option: -P:scalac-profiling:no-profiledb
[error] bad option: -P:scalac-profiling:show-profiles
I will try to keep my story short as possible.
So, how to make it all work for Scala 2.13. (Scala 2.13.3 in particular)
scalac-profiling is published only for Scala 2.12, but thanks for Open Source community, there is a forked version of it compiled for 2.13 here (Huge thanks to Leonard Ehrenfried).
Now, step by step, they are very similar to original article. However....
- Add
sbt-bloop
plugin toplugins.sbt
and run
sbt bloopInstall
- Download forked version of
scalac-profiling
coursier fetch --intransitive io.leonard:scalac-profiling_2.13:0.0.3
- Provide
scalacOptions
. Instead of editingbloop
files - I will just put them to mybuild.sbt
directly.
scalacOptions ++= Seq(
"-Xplugin:/Users/Home/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/leonard/scalac-profiling_2.13/0.0.3/scalac-profiling_2.13-0.0.3.jar",
"-P:scalac-profiling:no-profiledb",
"-P:scalac-profiling:show-profiles",
"-P:scalac-profiling:sourceroot:/Users/Home/projects/scala-performance/.bloop"
)
- Run
sbt compile
and you will see
...
Writing graph to /Users/User/projects/scala-performance/target/scala-2.13/classes/META-INF/profiledb/graphs/implicit-searches-1612543054297.flamegraph
- Feed this file to FlameGraph as described in the original article.
Be careful which color profile you use for .flamegraph
visualisation, otherwise you can end up having graph like this:
Available colors for ./flamegraph.pl
are:
--colors PALETTE # set color palette. choices are: hot (default), mem,
# io, wakeup, chain, java, js, perl, red, green, blue,
# aqua, yellow, purple, orang
hot
color profile looks like this: