Learn about Ruby on Rails 5, the first major release in three years. Rails 5 is faster, uses less memory, and spends less time performing garbage collection (GC). Rails 5 requires Ruby 2.2.2, optimizes common operations, has fewer library dependencies, and has fewer object allocations. The development environment is faster because it uses the Puma web server and has a file system monitor to know when code needs to be reloaded instead of having to check every file’s last modified time.
- View Offline
- [Voiceover] Let's begin by getting a big picture overview of Ruby on Rails version five. It's been three years since the last major release of Ruby on Rails. That was version four. And it's been about a year and a half since Rails 4.2 came out. And in the meantime, there've been a lot of improvements to Rails that make it feel faster, it uses less memory, and it spends less time doing garbage collection in memory. Now, this last point is largely about the fact that Ruby on Rails 5 now requires that we use Ruby 2.2.2 or greater.
Ruby 2.3 is already out, maybe later versions will be out, but Ruby 2.2.2 is required. And Ruby 2.2 offers garbage collection of symbols as well as something called incremental GC, which makes it feel faster. Ruby uses garbage collection to throw out unused objects in memory automatically. Previously, that meant that Ruby would periodically go through all the objects in memory, mark the ones that were still fresh or being used, and then make a second pass to remove the unmarked objects from memory.
The problem is that that GC sweep through memory takes some time, it can slow down your code while it's happening. Ruby 2.1 improved the speed of this process somewhat by classifying objects in memory based on the likelihood they would need to be garbage-collected. But a large collection could still slow things down. Well, now, in Ruby 2.2, we get incremental GC. And the basic idea is to break up the scanning and removal of objects so that the process happens incrementally, not all in one big sweep. So while the total work and the total time may still be the same, it's broken up among many smaller operations.
And the result is that Ruby feels much faster to use, and therefore so does Rails. In addition to these speed improvements in Ruby, Rails itself has gotten faster as well. The core team has optimized common operations, the code has fewer dependencies on other code in libraries, and there are fewer object allocations to memory. Now, that may seem like a small point that doesn't make much difference, but, as one example, link and URL generation in Ruby on Rails 5 is 44 percent faster. So it's no small thing. And overall you'll find that the development environment feels much faster.
The development environment uses the Puma web server now, instead of using WEBrick, and development mode used to check the modification time of all of your files in your project to know if anything had changed, so that it could automatically reload the development environment for you. But now, there is a file system monitor, which notifies Rails whenever something changes. There is no more requirement to check the modification times of all the files. And that makes development feel snappier when you are working. And on top of these performance improvements, Ruby on Rails 5 gives us many new features that we can use for development.
In the next chapter, let's take a look at the most significant new features.
- Using ActionCable to work with WebSockets
- Rendering templates independently of controllers
- Creating JSON API applications
- Using Turbolinks for faster page loads
- Working with new ActiveRecord features
- Leveraging improvements to date and time, parameters, and more
- Understanding deprecations and deletions