00:00:06.140
Hi everyone! I'm going to talk about Ruby 4. I might be the only one discussing Ruby 4 at this conference.
00:00:12.599
Currently, we are still on Ruby 3. I go by the name 'Kevin' instead of '4.' I joined Shopify in late July of this year, so I am still new to the company.
00:00:24.779
Though I've been discussing JIT compilers for about five years, I just recently joined the YJ team, where I am focusing on Ruby's JIT implementation.
00:00:37.559
In my presentation today, I will also discuss template engines including Haml and ERB, the default template engine for Ruby. These projects have been supported by my sponsors, and I'm grateful to GitHub for their support.
00:00:58.379
I have replaced the Haml 5 template engine with Homily, which I first introduced at RubyKaigi in 2015. Finally, Homily has become the default implementation for templates.
00:01:12.299
Haml 5 and Homily 6 are not the same; the latter is a complete redesign. If you are using Slim, it is currently the slowest template engine, and I encourage you to switch to Homily for better performance.
00:01:30.840
I don't expect all of you to have experience with JIT, so I will explain how it works. The Ruby interpreter typically compiles Ruby source code into an abstract syntax tree, which can be slow to traverse.
00:01:46.560
Instead, we compile it into a more sequential code to enhance performance. This involves pushing arguments onto the stack and executing them to get a return value. This approach is how the Ruby virtual machine operates, which Kohg built.
00:02:22.380
These days, we are optimizing further by generating machine-specific code instead of simulating the behavior with Ruby's virtual machine instructions. This example demonstrates how the JIT translates into assembly code.
00:02:46.920
The instruction sequence generated can be compared to bytecode, but since we are working on a broad scale, we refer to it as an instruction sequence. You can view this instruction sequence by using the 'D' method for analysis.
00:03:06.599
As you analyze the instruction, you'll find it greatly simplifies optimization for Ruby scripts. I encourage you to focus on writing beautiful Ruby code while JIT handles the low-level details.
00:03:28.620
Currently, Ruby's implementation includes two JIT compilers. The first is MJIT, introduced in Ruby 2.6, and the second is WJIT, which you might have heard about in recent discussions.
00:04:20.160
For performance benchmarking, we have a suite called 'widget bench' that helps analyze and compare different implementations. The benchmarking is crucial as it allows us to measure real-world application performance.
00:04:50.520
Currently, MJIT is not optimally performing, but WJIT also shows potential. Our ongoing efforts aim to improve overall efficiency; for instance, we aim to ensure that WJIT optimizes Rails applications effectively.
00:05:29.220
In the realm of benchmarks, we categorize them into headlining benchmarks that reflect real-world applications. For example, Rails benchmarks are essential as they directly relate to applications generating revenue.
00:05:55.740
Another interesting benchmark is the NES emulator found in our other category benchmarks. While MJIT helps improve many areas, it is essential to ensure that all benchmarks align with the Ruby developers' expectations.
00:06:34.920
As we progress with Ruby 3.1, the JIT compilers are evolving. While MJIT has limitations, WJIT is being refined to enhance performance significantly, and we are committed to supporting both options for different use cases.
00:07:14.220
The architecture of WJIT is shifting to incorporate more robust features. From Ruby 3.1 onward, you can expect better performance as we integrate changes that allow Ruby to optimize more effectively.
00:07:58.580
The transition to a new architecture will provide us room to implement various capabilities and optimizations that push Ruby performance to new heights.
00:08:29.040
On a more experimental note, the JIT compilers will allow for greater flexibility. Features like monkey patching will enable developers to customize how JIT operates, providing an exciting avenue for advanced Ruby programming.
00:09:07.920
The flexibility we are instituting means that developers will increasingly write their own JIT implementations and integrate them with Ruby efforts seamlessly.
00:09:40.920
As a community, we should embrace this flexibility and utilize it to further the Ruby ecosystem. I encourage everyone here to explore these new avenues and test the developments.
00:10:00.400
In conclusion, the evolution of Ruby, specifically with the JIT improvements, aims to bring Ruby closer to speeds achieved by languages such as Java and JavaScript. The goal is clear: we want Ruby to be competitive and meet modern development standards.
00:10:51.780
As we push towards Ruby 4, I envision a version of Ruby that can keep pace with languages optimized for performance while maintaining the elegance and simplicity that Ruby developers cherish. Thank you for your attention!