Saturday, December 25, 2021

Opal 1.4: Ruby 3.1, performance, and bundle size

We are proud to announce an immediate availability of Opal 1.4!

Opal is a Ruby to JavaScript (ES5) compiler allowing you to write frontend code in pure Ruby (and a lot more!).

This version of Opal is about compatibility with Ruby 3.1 and lots of internal improvement around performance, code size, and readability of the generated code. Opal 1.3 was released just about 2 months ago, but we really wanted to get 3.1-level compatibility out around the time Ruby 3.1 is released this Christmas.

As always, you don't need to run Opal with Ruby 3.1 to benefit from the 3.1-level features, Ruby 2.6 will do just fine :)

New Ruby 3.1 features

Class#subclasses, Class#descendants, syntax like h = {a:} is all supported, along with a lot of other Ruby 3.1 features. You can take a look at our changelog or Ruby 3.1 release notes to read about all the new features we have. Big thanks to the people working on whitequark/parser - their hard work made this possible - it didn't require from us any effort to support the new syntax features!

We also added some features from older versions of Ruby that we missed. For example: Kernel#local_variables and Enumerator::ArithmeticSequence.

Generated size optimization

Despite the fact, that we added a lot of features, Opal 1.4 is 20% smaller than Opal 1.3 (minified) and just a little bit larger than Opal 1.0.0. Your web applications should be about 10% - 20% smaller uncompressed, which should directly translate to better performance and load times. Please take a look at our blog post if you are interested in how we achieved this. In addition to that the produced code is way more readable than before.

Jan Biedermann who develops isomorfeus, a Preact-based framework using Opal reported the following numbers:

                                 1.3.2  1.4.0.alpha1
Max asset sizes: minified:       600kb  502kb
gzip:                            150kb  132kb
isomorfeus-redux require time:    19ms   19ms
isomorfeus-preact require time:   52ms   46ms
isomorfeus-preact start_app! time: 6ms    7ms
application load_time:            78ms   73ms
10000 Native DIV Elements took:   10ms    8ms
10000 DIV Elements (S p) took:    78ms   77ms
10000 DIV Elements (S b) took:    95ms   78ms
10000 Native Components took:    115ms   95ms
10000 Function Components took:  203ms  192ms
10000 Preact Components took:    181ms  160ms
10000 Lucid Funcs took:          318ms  306ms
10000 Lucid Components took:     367ms  339ms
10000 Styled Lucid Comp took:    469ms  433ms
10000 Themed and Styled LC took: 505ms  473ms

PromiseV2 is now declared stable!

From my personal experience, it's very simple to replace the old Promise with the new PromiseV2 and I didn't have any issues. While in Opal 1.2 and 1.3 it was a developer preview, we now declare it as stable and a recommended way to do Promises.

Conclusion

Merry Christmas everyone and we hope that Opal 1.4 will be a present you will all enjoy!


Resources



from Hacker News https://ift.tt/3ppUM3z

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.