|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Announcing Scala.js 1.16.0 |
| 4 | +category: news |
| 5 | +tags: [releases] |
| 6 | +permalink: /news/2024/03/19/announcing-scalajs-1.16.0/ |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +We are excited to announce the release of Scala.js 1.16.0! |
| 11 | + |
| 12 | +The biggest highlight of this release is that we added a Scala.js-specific minifier. |
| 13 | +When combined with a general-purpose JavaScript minifier, our minifier should bring most of the code size benefits of the Google Closure Compiler when the latter cannot be enabled, notably when emitting ECMAScript modules. |
| 14 | + |
| 15 | +Scala.js 1.16.0 also upgrades by default to the standard library of Scala 2.12.19 and 2.13.13. |
| 16 | + |
| 17 | +Read on for more details. |
| 18 | + |
| 19 | +<!--more--> |
| 20 | + |
| 21 | +## Getting started |
| 22 | + |
| 23 | +If you are new to Scala.js, head over to [the tutorial]({{ BASE_PATH }}/tutorial/). |
| 24 | + |
| 25 | +If you need help with anything related to Scala.js, you may find our community [in `#scala-js` on Discord](https://discord.com/invite/scala) and [on Stack Overflow](https://stackoverflow.com/questions/tagged/scala.js). |
| 26 | + |
| 27 | +Bug reports can be filed [on GitHub](https://github.com/scala-js/scala-js/issues). |
| 28 | + |
| 29 | +## Release notes |
| 30 | + |
| 31 | +If upgrading from Scala.js 0.6.x, make sure to read [the release notes of Scala.js 1.0.0]({{ BASE_PATH }}/news/2020/02/25/announcing-scalajs-1.0.0/) first, as they contain a host of important information, including breaking changes. |
| 32 | + |
| 33 | +This is a **minor** release: |
| 34 | + |
| 35 | +* It is backward binary compatible with all earlier versions in the 1.x series: libraries compiled with 1.0.x through 1.15.x can be used with 1.16.0 without change. |
| 36 | +* It is *not* forward binary compatible with 1.15.x: libraries compiled with 1.16.0 cannot be used with 1.15.x or earlier. |
| 37 | +* It is *not* entirely backward source compatible: it is not guaranteed that a codebase will compile *as is* when upgrading from 1.15.x (in particular in the presence of `-Xfatal-warnings`). |
| 38 | + |
| 39 | +As a reminder, libraries compiled with 0.6.x cannot be used with Scala.js 1.x; they must be republished with 1.x first. |
| 40 | + |
| 41 | +## Enhancements with compatibility concerns |
| 42 | + |
| 43 | +### Changes to the IR and linker APIs |
| 44 | + |
| 45 | +For tooling authors who directly manipulate the IR and linker APIs, there have been some breaking changes in that area. |
| 46 | +This is in line with our version policy for the linker APIs. |
| 47 | + |
| 48 | +The most likely changes you may hit are: |
| 49 | + |
| 50 | +* `FieldName` is now a composite of the defining `ClassName` and a `SimpleFieldName`. |
| 51 | +* `StoreModule` has no parameter anymore; it implicitly applies to storing the `this` value of the enclosing module class. |
| 52 | + |
| 53 | +## Enhancements |
| 54 | + |
| 55 | +### Scala.js-specific minifier |
| 56 | + |
| 57 | +In the `fullLink` mode, the Scala.js linker now includes dedicated code size optimizations. |
| 58 | +They are mostly useful when the Google Closure Compiler is deactivated, which is the case by default when emitting ECMAScript modules. |
| 59 | + |
| 60 | +The most important optimization is that it compresses all *property* names (fields and methods) of Scala classes. |
| 61 | +It computes how frequently each one is used across the codebase, and assigns shorter names to the most frequent ones. |
| 62 | + |
| 63 | +Renaming local and global variables and functions in this way is a standard feature of general-purpose JavaScript minifiers. |
| 64 | +However, in general they cannot rename *properties* without breaking the semantics of JavaScript programs. |
| 65 | +This is why Scala.js has leveraged Closure since the very first relase. |
| 66 | +Closure's so-called "advanced optimizations" assume that the JavaScript program fits in a specific subset of semantics, which allows it to rename properties. |
| 67 | + |
| 68 | +Unfortunately, the way Closure handles ES modules is incompatible with what we need. |
| 69 | +Closure is therefore disabled when emitting ES modules from Scala.js. |
| 70 | +This has resulted in large bundle sizes for users of ES modules. |
| 71 | + |
| 72 | +Our minifier, which is aware of our types and of Scala.js semantics, fills that gap between Closure and general-purpose minifiers. |
| 73 | +When combined with a general-purpose minifier such as the one bundled with Vite, the new optimizations bring code size around 15% bigger than Closure. |
| 74 | +Contrast that with the previous status quo, which was several *times* bigger than the Closure output. |
| 75 | + |
| 76 | +If, for some reason, the new optimizations cause issues in your case, you can disable them with |
| 77 | + |
| 78 | +{% highlight scala %} |
| 79 | +scalaJSLinkerConfig ~= { _.withMinify(false) } |
| 80 | +{% endhighlight %} |
| 81 | + |
| 82 | +Please let us know if you encounter any issue with this new mode. |
| 83 | + |
| 84 | +### Other code size improvements |
| 85 | + |
| 86 | +In addition to the minifier, Scala.js 1.16.0 generally produces smaller .js files. |
| 87 | +This is the result of various code size optimizations that we apply in all configurations. |
| 88 | + |
| 89 | +In particular, the optimizer now eagerly "dealiases" `val` fields of top-level objects if they are simple and if the object's initializer can be proven to be pure. |
| 90 | + |
| 91 | +### Reduced memory consumption of the linker |
| 92 | + |
| 93 | +The linker is generally optimized for *incremental* runs, which naturally requires to maintain a lot of caches in memory. |
| 94 | +We have started work on reducing the memory consumption of the linker without compromising on speed. |
| 95 | +This release already ships with the first installment of these improvements, reducing the memory footprint of the linker by 10%. |
| 96 | +If interested, you can find out the details [in the relevant pull request #4917](https://github.com/scala-js/scala-js/pull/4917). |
| 97 | + |
| 98 | +## Bug fixes |
| 99 | + |
| 100 | +Among others, the following bugs have been fixed in 1.16.0: |
| 101 | + |
| 102 | +* [#4929](https://github.com/scala-js/scala-js/issues/4929) Assertion failed: Trying to move a local VarDef after the super constructor call of a non-native JS class |
| 103 | +* [#4949](https://github.com/scala-js/scala-js/issues/4949) Wrong pretty-printing of JS tree that *starts* with an object lit |
| 104 | + |
| 105 | +You can find the full list [on GitHub](https://github.com/scala-js/scala-js/issues?q=is%3Aissue+milestone%3Av1.16.0+is%3Aclosed). |
0 commit comments