-
Notifications
You must be signed in to change notification settings - Fork 206
Cache ScalaJS linkers for incremental linking #1761
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
Conversation
09cd90c
to
6e4abdc
Compare
Avoid caching fullLinkJS linker to save memory
6e4abdc
to
fc37fc5
Compare
val useClosure = input.isFullLinkJS && input.moduleKind != ModuleKindJS.ESModule | ||
|
||
val config = StandardConfig() | ||
.withOptimizer(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.withOptimizer(true)
should be used also with fastLinkJS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withOptimizer(true)
is the default anyway. ;)
@@ -51,6 +53,41 @@ object JsBridge { | |||
} | |||
override def trace(t: => Throwable): Unit = logger.trace(t) | |||
} | |||
private object ScalaJSLinker { | |||
private val cache = TrieMap.empty[Path, WeakReference[(JsConfig, Linker)]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WeakReference
s are not the best choice for memory-sensitive caches. Use a SoftReference
instead.
val useClosure = input.isFullLinkJS && input.moduleKind != ModuleKindJS.ESModule | ||
|
||
val config = StandardConfig() | ||
.withOptimizer(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withOptimizer(true)
is the default anyway. ;)
Co-authored-by: Sébastien Doeraene <sjrdoeraene@gmail.com>
This PR enables Scala.js incremental linking by caching the linker in memory in a concurrent map.
To avoid wasting memory (since bloop has a global instance which is long running), this avoid caching the release linkers. Also it caches one linker per output path. If you change the
JsConfig
the previousLinker
instance will be garbage collected and a new one will be saved in the map.It uses a
scala.collection.concurrent.TrieMap
as a mutable map implementation.It also stores
SoftReference
s so if the GC needs memory it can drop a linker to make space for something else.The implementation was adapted from the one existing in the Mill build tool.