what’s new in the programming language and what’s changed

what’s new in the programming language and what’s changed

These days, a new release of the dynamic object-oriented programming language Ruby 3.3.0 has appeared. It incorporates the best features of many other programming languages, including Perl, Java, Python, Smalltalk, Eiffel, Ada, and Lisp. As for the project code, it is distributed under the BSD (2-clause BSDL) and Ruby licenses, which refer to the latest version of the GPL license and are fully compatible with GPLv3. Details – under the cat.

What has changed and what has been added?

  • One important change is the performance optimization of the YJIT compiler. It is developed by the developers of the Shopify e-commerce platform. This is done as part of a project to improve the performance of Ruby applications that use the Rails framework and call a lot of methods. YJIT uses basic block versioning (LBBV – Lazy Basic Block Versioning) instead of method processing and is fully implemented in the form of an integrated JIT compiler written in the Rust language. With LBBV, the JIT initially compiles only the beginning of the method, and compiles the rest later after the execution process has determined the types of variables and arguments used.

  • When conducting tests, including running the Optcarrot emulator, the performance when using the compiler is about three times higher than when running the interpreter. It is also worth noting that the new version provides allocation of registers for virtual machine stack operations. In addition, the range of compiled calls with optional arguments has been expanded, inline deployment of basic and specialized methods has been implemented, and separate optimizations have been added for the operations “Integer#*”, “Integer#!=”, “String#!=”, “String# getbyte” , “Kernel#block_given?”, “Kernel#is_a?”, “Kernel#instance_of?” and “Module#===”. The compilation speed has been significantly increased.

  • And the memory consumption for storing metadata is also reduced, plus the generation of more compact code for the ARM64 architecture is ensured. Also disabled the Code garbage collector (“–yjit-code-gc”), which dynamically frees generated machine code that is not in use, but causes performance to suffer during garbage collection. A new RubyVM::YJIT.enable method has been introduced to control the enablement of YJIT at runtime without having to run it with a specific command line option or environment variable. And to top it all off, the expansion of the statistics that are displayed when the “–yjit-stats” option is specified has been implemented. Added performance profiling (–yjit-perf) and trace (–yjit-trace-exits) modes.

  • The Prism parser also appeared in the main composition. It is included in the form of the libprism C library used in the CRuby interpreter and a Ruby gem package that provides a publicly available API for the downward recursive parsing of Ruby code, suitable for use in working projects instead of the Ripper parser. A plus of the parser in the flexible handling of errors in the code. To enable the parser, you need to use the “ruby –parser=prism” option or the RUBYOPT=”–parser=prism” environment variable. To analyze code in applications, there are methods Prism.parse(source) to get an AST representation of the code, Prism.parse_comments(source) to extract comments from the code, and Prism.parse_success?(source) to check for errors in the code.

  • Previously, the Bison external package was used to create parsers. Now Lrama is used instead, which provides a Ruby implementation of the LALR algorithm. It supports Bison-compatible grammar definitions (parse.y) used in CRuby, implements advanced features such as error handling and parameterized rules (?, *, +).

  • Added new RJIT JIT compiler. It is written completely and entirely in Ruby. Its advantage is the absence of the need to work with the C compiler. RJIT supports only x86-64 architecture and Unix-like platforms.

  • The “M:N” thread scheduler appeared. It allows you to use a limited number of operating system threads to handle threads in Ruby code to reduce the overhead of creating and managing threads. By default, 8 OS threads are used (can be changed through the RUBY_MAX_CPU environment variable). Using the “M:N” scheduler can cause compatibility issues with C extensions, so it is disabled by default for the main Ractor class, but enabled for non-main. To force the scheduler to be enabled, the RUBY_MN_THREADS environment variable must be set to 1.

  • The capabilities of the IRB (REPL, Read-Eval-Print-Loop) interactive calculation shell have also been expanded. For example, added IRB(REPL, Read-Eval-Print-Loop) calculation. And support for multi-page viewing of ls, show_source and show_cmds command output has also appeared. Implemented experimental support for autocompletion of input that takes data types into account. Commands for changing font color and style are presented.

  • The developers decided to deprecate the call to the “it” method without arguments in a block without parameters (for example, “[1, 2, 3].each {puts it}”).

  • Also, in RubyGems and Bundler, the appearance of a warning is activated in case of specifying in “require” gem packages abbrev, base64, bigdecimal, csv, drb, getoptlong, mutex_m, nkf, observer, racc, resolv-replace, rinda and syslog, in Gemfile or gemspec . In future versions of Ruby, these gem-packages will be integrated into the core composition.

  • Finally, all versions of built-in and included standard library gem modules have been updated.

Related posts