-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable classloader caching for macros and plugins in 2.13 ? #548
Comments
The blocker for this change is cache invalidation. In retronym/scala#27, I propose a generic way of getting rid of this (arguably complex) problem in the compiler. However, I'm skeptical we'll be able to enable this feature by default without the help/intervention of build tools. The general idea is to have a This is a powerful and generic way of solving this problem. In all the cases I know, the clients of the compiler already have the information about what things changed or not in the classpath (or in the build DAG), and this information is the source of truth. With this approach, we can support classloader caching "by default" in all Scala codebases with some tweaks to Zinc (while Bazel can instead pass the hashes themselves to the compiler). Zinc already reasons about changes to classpath because it needs to invalidate changes in external projects, so it can trivially pass this information to Scala's 2.13 compiler bridge. In the linked ticket, I also propose an akin mechanism to invalidate symbols that changed in the symbol table, but that's partially unrelated to this topic as it has more to do with the invalidation mechanism of resident compilation. |
I feel I haven't done a good job at fully selling all the benefits of this approach. To me, the most important one is the removal of duplication. If we have a big classpath for a build of a 100 modules and we implement the invalidation logic inside the compiler, the compiler will need to read the timestamps of every classpath entry in every compilation of a project. That is a lot of work. By letting the build tool tell the compiler which things changed and which didn't, we solve this problem as the state that keeps track of the invalidation comes from outside the compiler and is global to the build tool knowledge. If I have such hook, bloop and other build tools can implement an efficient way of reading timestamps or computing checksums of compiler inputs in a lazy way (context: scalacenter/bloop#32). Here's a better way a build tool could implement this than the status quo:
When does the build tools needs this information? It turns out that it does in several cases:
All these use cases happen on a per-project basis, so to reiterate having a global oracle that provides this information to the use sites directly is a big win because most of the classpath entries are shared in the projects of a build. |
@jvican and I talked about this in https://gitter.im/sbt/zinc-contrib. I have an imminent PR to sbt and io that does something quite similar to what is proposed in the above comment. |
@retronym are you working on this for 2.13.0-RC1? |
Not for RC1, unfortunately. I do some more foundational parts merged or queued which make it safer/easier to use, namely:
|
In scala/scala#6412 the caching that was added in 2.12.5 was turned off by default:
Can we reenable this for 2.13 now? The benefits look pretty good, from scala/scala#6314:
/cc @adriaanm @retronym @jvican
The text was updated successfully, but these errors were encountered: