While I love Scala the language, and Scala.js the project, I'm a little put-off by the size of the eventual JS bundle, even in fullOptJS mode.
My immediate need is to create a small-ish library for use in the browser. >150kb is a big ask, and arguably comparable tools like BuckleScript/ReasonML promise fast execution and tiny bundles.
Will Scala.js start producing smaller bundles in the foreseeable future?
Short answer: unlikely.
When designing a language, there are always trade-offs to make. In particular, cross-compiling a language across JavaScript and another target typically leads to a series of more-or-less conflicting goals. For example, producing "idiomatic, readable JavaScript" is often at odds with producing "highly optimized JavaScript".
In that space, the main design goals of Scala.js are, in decreasing order of importance:
While code size is definitely a concern, as you can see, it sits pretty low on the list of main design goals. This means that code size concerns will typically yield to other concerns on the list.
In particular, it is often at odds with the requirement of compatibility with Scala/JVM. Indeed, Scala has a pretty large standard library, notably collections, and many parts of that library inter-depend on each other. This means that as soon as you use, say, a Scala List
, your code needs a significant portion of the standard Scala collections library. This portion of the stdlib is what makes most non-trivial Scala.js programs weigh above 150 KB.
Since the above conditions (design goals + collections library inter-dependencies) are unlikely to change in the foreseeable future, it is equally unlikely that Scala.js will suddenly produce less code.
Strictly speaking, it is possible to write a Scala.js application producing only 10 KB or a bit more. But in order to do so, you must be very careful not to use any parts of the collections library, ever. You should use js.Array
s, js.FunctionN
s and js.Promise
s everywhere, instead of List
s, =>
functions and Future
s, for example. At this point, Scala.js stops being Scala, and hence you would be better off with another language (e.g., BuckleScript).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With