Do you love Christmas gifts? Just wait for the 2020 winter holidays!
2020 will be a big year for the whole Ruby community.
The Ruby founders have a really great present in store for us – the release of Ruby 3.0!
The gift is beautiful, but there are also lots of cool features inside.
Recently there have been some rumors of RoR’s death. And I believe this update will smash those rumors to pieces.
Ruby performance: no more issues
Everybody knows Ruby is the perfect language for MVPs, prototypes, and startups, but Ruby’s speed is definitely the biggest issue with the programming language. People claim that the language needs to be faster for massive projects. Do you agree? If so, you’ll enjoy the updated Ruby. In 2020, Ruby 3 will be three times faster than the previous version thanks to Ruby performance optimization.
The current Ruby 2.6 version still has some Ruby on Rails performance issues, especially with memory usage. The problems occur when programmers create new objects which are then swept away and “fragment the heap.” When this happens, a lot of space for such objects remains unused, and we use more memory than is actually needed.
Great news: in Ruby 3 this problem will be solved with a garbage compactor (GP).
This GP has some key features:
Object separation. While some objects are pinned, the rest can be transferred to the heap.
Auto-compaction. No special commands are required to compact the garbage – in the new version automatic compaction is fully supported.
One of the most promising updates for Ruby CPU performance is the new Ruby JIT.
Another new feature that might significantly improve the programming language’s performance is the Medium Internal Representation JIT compiler, which is lightweight and convenient to work with.
We hope that this update will actually be included in Ruby 3 since it might solve Ruby’s issues and result in significant performance improvement beyond the current JIT.
The Latest Ruby version: concurrency changes
There are some programming problems in Ruby, and these imperfections will be fixed in the 3×3 era.
Falcon Rack web server and Async
(a composable asynchronous I/O framework for Ruby)
Together, these features do not block I/O (input and output data). In contrast to current web servers, which block I/O and take up a lot of additional time, async frees your server to accept other requests while it waits on your database, memory store or API calls.
Static type checker
If you set the necessary configurations, the type checker will validate input data.
But there is a paradox: the Ruby team wants to use backward compatibility but doesn’t want to add heavy type declarations.
Therefore, this part of the update for Ruby programming problems is a little uncertain, since the Ruby team does not have any proposed solutions yet.
The current version of Ruby has a global VM Lock (GVL), which makes it impossible to use parallel computing. The Ruby update promises to change this. With Ruby 3, programmers will be able to usefully parallel threaded computation.
That means that Ruby now is single-flow language. With Ruby 3, it will be possible to execute parallel tasks, which makes the whole process way faster.
Static analysis for clearer code
Static analysis is an additional tool that helps to check the code after the tests. The good thing – your work gets an additional checkup. The bad one – static analysis relies on type annotations, which in their turn cause Ruby challenges as the repetitions in code.
There are two major solutions:
On June 20, Stripe team announced the Sorbet typechecker, that is still in early stages, but is mature enough to run on the majority of Ruby code. You can check it out, but be careful, as far as your experience might still be rough.
Sorbet uses inline type annotations, unlike Steep’s parallel annotation files. This way, Sorbet appears to be fast, but Steep allows you to keep type annotations in a separate file. Therefore, the code will be clearer and more laconic than it is currently.
Some bad news: we can face some possible Ruby coding challenges with the transmission of parameters. The update isn’t automatic – once Ruby 3 is out, you’ll need to update it manually. That means that in some cases the code written on the previous Ruby versions may be deprecated after the Ruby 3 update.
Some good news: there is a solution. The latest version (before the Ruby upgrade) will give developers some warnings. For instance, if this or that feature is planned to be changed in Ruby 3, you’ll find the prompts about it right in the log. Therefore, you will see beforehand what needs to be fixed after Ruby 3 is out.
More good news: there is a plan to add backward compatibility for all the previous Ruby versions, so it won’t be too hard to switch from one version to another.