What’s new in Ruby 3.0?

Tram Ho

According to some leaked information I know, the possibility that RUBY 3.0 version will be released on Christmas this year (2020). I have read some articles about problems encountered by Ruby and Ruby on Rails ( https://sloboda-studio.com/blog/tech/is-ruby-on-rails-dying/ ). But in my opinion, Ruby is still thriving and I believe this RUBY 3.0 will bring some great changes in all aspects.

Today I would like to take a look at some features and improvements that can be released in the upcoming version Ruby 3.0 .

There are 4 main points covered in this version 3.0 are: Performance (performance), Concurrency (concurrent), Static analysis (static statistics) and Transition issues (up / down version issues)

Performance: no more issues

Memory performance

In Ruby 2.6 there are still backlog some performance issues of Ruby on Rails and especially problems with memory usage.

This problem occurs when we create a new object and then get fragmented and scattered in memory resulting in a portion of CPU memory being occupied.

To get around this problem Ruby 3.0 used garbage compactor , which can be understood as a garbage collector . Some of the features of GP :

  • Object separation : Separate objects from each other, except those in use, the rest can be put into the heap.
  • Auto-compaction : This feature allows to automatically clean up unnecessary memory without having to run any other commands.

CPU performance

One of the most promising updates on Ruby CPU performance is the new version of Ruby JIT. Hopefully the new version of JIT will improve the problems of Ruby and bring significant performance beyond JIT in the current version.

Concurrency Changes

Falcon Rack web server and Async

Falcon Rack is an asynchronous Input / Output framework that can be combined with Ruby. Along with Async , Falcon Rack will no longer block Input / Ouput data. Unlike the current web server, it will block I / O and some of the following processes need more time to wait until the process is in progress using resources (resources here can be memory, database). Asynchronous frees the server and allows receiving other requests while it is still waiting for the database, memory store or API call

Parallel computation

Current ruby ​​versions support global VM lock (GVL) , which allows us to use parallel computing. In version 3.0, we can use parallel threaded computation.

Meaning ruby ​​is currently a single-threaded language. With version 3.0, it can handle multiple tasks in parallel meaning the processing time will be faster.

Static analysis: Help clearer code

Static analysis is a tool that allows users to test code after testing. The plus point of this tool is that it helps our code to be more correct in design standards, but in return it works based on annotations written in ruby ​​files, so it will be difficult to avoid duplication in code.

There are 2 main methods:

  • Steep
  • Sorbet

In June 2020, Team Stripe released a type-checker called Sorbet, which, despite being an early version, is also quite powerful for Ruby. Mn can see more details here . Sorbet uses inline type annotations while Steep parallel annotation files . That is why the Sorbet seems fast.

Backward compatibility

Switching between different Ruby versions is no longer a problem and there will be warnings displayed in logs that make fixing the error faster.

Special features

  • Right Assignment: variable_value => variable_name
  • Some updated libraries: RubyGems 3.2.0.rc.1, Bundler 2.2.0.rc.1, IRB 1.2.6, Reline 0.1.5

=> Above is some information I gathered about the new features that may be available in Ruby 3.0. Everyone, let’s celebrate the launch of this year’s chrismas season. There is some information I do not understand so I did not include it in the article. You can read more at the links below the reference to better understand.

Thank you everyone for reading

References

Share the news now

Source : Viblo