00:00:14.450
Good afternoon, RailsConf '17! We'll be talking about the Helix project today.
00:00:21.300
First, I hope you're having a great day.
00:00:27.150
As you can see, I'm here on the Rails forum — yes, that's what we're doing.
00:00:33.780
The most important thing to remember is to run 'bundle update rails'.
00:00:38.910
And as you can see, we are successful!
00:00:46.289
This is actually a sponsored talk by Skylight. I am required to sell you something, but honestly, I don't feel comfortable just promoting.
00:01:10.320
So, instead of selling you on model stuff, I thought I would highlight some really useful talks.
00:01:16.490
There's another talk today that might be of interest. It’s called '160', about using a single codebase for web and mobile applications.
00:01:29.250
If you have to leave, that’s fine.
00:01:36.210
As for myself, I am Grateful, I am here today to talk about a project called Helix, which I discussed briefly last year.
00:01:52.770
This project is an exciting development because Ruby is fast, but we also know it can be slow.
00:02:10.299
Most of the time, Ruby’s speed is not a big concern; however, there are occasions when performance really does matter.
00:02:17.020
To illustrate, let's look at some CPU-intensive workloads that might present challenges.
00:02:31.000
I've been working on this project, along with my colleague, Yehuda Katz.
00:02:37.840
Together, we are both RailsConf 2017 alumni, and we also work on the Ember.js framework.
00:02:49.930
At Skylight, we are hiring senior engineers, so if you're interested, please come talk to us.
00:03:05.860
Now, let me tell you about one feature we implemented this year called 'grades', which compares your app's performance to that of our other customers.
00:03:17.530
That being said, now let's dive into the Helix project. Last year, I talked about Helix and how we have been working on improving Rails.
00:03:42.159
In brief, Helix is an open-source toolkit designed to make writing native Ruby extensions in Rust easier.
00:04:04.419
We’ve dedicated a lot of time to Helix and are excited to share what we have come up with.
00:04:10.299
Everyone here loves writing Ruby; it’s an amazing language, but we also face performance challenges.
00:04:24.720
For example, Ruby applications are often I/O bound, and developers typically spend a great deal of time waiting for database responses.
00:05:06.699
Even when it doesn’t matter, there are times when performance is essential, especially with CPU-heavy workloads.
00:05:24.009
To address performance, one effective approach is using C extensions.
00:05:30.039
This is how Ruby successfully optimized libraries like Date and Pathname.
00:05:38.740
Years ago, Sam Saffron discovered that the 'blank?' method was a hotspot in Discourse.
00:05:44.140
He proceeded to write a C library called 'fast_blank' that sped up operations dramatically.
00:06:01.630
So why don't we do more of this? What’s stopping us from writing more Rails functionality in C?
00:06:07.330
In a nutshell, while C is fast, it's also quite complex and unsafe.
00:06:12.700
Any small mistake could lead to a segmentation fault, which is something we're all wary of.
00:06:18.340
Most developers prefer to stick with pure Ruby to avoid these risks.
00:06:24.850
At Skylight, we faced similar challenges.
00:06:30.070
We found that while our first version of the Skylight agent worked fine in Ruby, we struggled to add a lot of the features we wanted due to performance overhead.
00:07:11.260
Originally, we thought we could solve our performance issues with C or C++ extensions, but we encountered similar burdens.
00:07:23.590
This led us to consider trying Rust.
00:07:29.620
The first trials went so well that we eventually migrated much of our core functionality to Rust.
00:07:38.140
Rust is a compiled, statically typed language that is exceptionally fast.
00:07:49.580
What makes Rust particularly appealing is its advanced type system and ownership model, which guarantee memory safety without a garbage collector.
00:08:10.420
This aspect allows you to avoid data races, making it suitable for concurrent programming.
00:08:25.430
High-level programming languages such as Ruby often present a trade-off between abstraction and performance.
00:08:52.090
However, in Rust, you can frequently use high-level abstractions without paying the overhead cost.
00:09:07.900
The Rust compiler is capable of optimizing code efficiently, often yielding better performance than manually crafted loops.
00:09:35.500
To illustrate this, when we ported the fast_blank example to Rust, we achieved similar performance as the C version with a simple one-liner.
00:09:56.229
While the original implementation required about 50 lines of boilerplate code, we have created Helix to eliminate the unnecessary boilerplate, allowing developers to write cleaner, more concise Rust code.
00:10:22.269
In the past, there was a clear distinction between scripting languages and systems languages, with the former primarily handling I/O operations.
00:10:39.610
However, Helix allows you to harness the power of Rust while writing Ruby, avoiding the need to compromise on performance.
00:11:02.649
Essentially, you can begin with Ruby and transition your CPU-bound logic to Helix as needed.
00:11:21.030
So, to summarize my talk from last year, we’ve made substantial progress in making Helix accessible to everyday developers.
00:11:32.110
We’ve streamlined the setup process and minimized boilerplate code significantly.
00:11:39.610
We are focusing on making it feasible for developers to incorporate Rust code into their existing Rails applications, targeting CPU-intensive tasks to optimize runtime performance.
00:12:09.480
Now, let me show you a demo of a very simple Rails app that flips text upside down using our Rust functionality.
00:12:24.140
We are going to generate a Rails app that allows text input, and upon clicking a button, it will display the reversed text.
00:12:51.860
The implementation relies on our previously defined Rust methods for heavy text transformations.
00:13:17.430
Furthermore, I will show you how seamless it is to deploy Rust alongside Ruby in a Rails application.
00:13:29.990
As we start by generating our Rails app, we're using the latest release candidate, and we're skipping Active Record to keep things simple.
00:13:51.349
Now that our Rails server is running, we will add the Helix gem to our Gemfile and then install it.
00:14:09.090
From there, we use Helix's generator to create the necessary Rust files.
00:14:19.200
The generated files will include both Ruby and Rust components, structured to help streamline your development process.
00:14:35.700
Next, I will implement the core functionality in Rust to ensure efficient processing of the text flip.
00:14:56.960
We will define a Rust method that performs the reversal of the input text.
00:15:06.450
Now that we can compile this Rust code, I will run it to see if our implementation works.
00:15:29.990
After running our tests, we will ensure everything functions correctly before deployment.
00:15:39.490
The Helix project has allowed us to write concise and efficient code, seamlessly combining Rust's performance with Ruby's ergonomics.
00:15:54.490
As we continue to build on this framework, we aim to make the integration as smooth as possible for developers.
00:16:09.200
After setting everything up, we will deploy this app on Heroku.
00:16:33.000
This deployment process is straightforward. You just push your code to Heroku's Git repository.
00:16:46.170
Our app is now up and running, with the Rust code successfully integrated into the Ruby on Rails framework.
00:17:05.690
As for the use cases for Helix, it is particularly suitable for CPU-intensive tasks.
00:17:20.520
Heavy computational problems with simple input types can benefit greatly from Rust's performance.
00:17:40.460
Additionally, integrating existing Rust libraries into Ruby applications is another strong advantage.
00:18:01.900
Helix enables a user-friendly interface to access high-performance libraries written in Rust.
00:18:27.620
Using Helix, you can build background jobs or perform CPU-intensive processing in Rails.
00:18:48.300
We'll also provide detailed documentation on our roadmaps and features as they develop.
00:19:05.490
We invite you all to check out our resources and consider contributing.
00:19:18.230
We are looking forward to engaging with both new and experienced developers interested in exploring the potential of Helix.
00:19:33.940
That's all from me for now. Thank you for your attention!
00:19:56.860
I hope you enjoy the rest of RailsConf.