My notes from RailsConf 2016
It was my second RailsConf. Last year I went to the RailsConf to give a talk, and this time, I had an entirely different conference experience as an attendee. I had a lot of time since I didn’t have to prepare!
This year I decided to take a few notes and facts from the talks I attended to share it on my blog. You will find a link to slides and my summary of the talk. And at the end of the post, you can find links to all keynotes.
I Can’t Believe It’s Not A Queue: Using Kafka with Rails
- Kafka is a distributed, partitioned, replicated commit log service. You can use it for distributed pub/sub messaging
- Kafka is distributed, which means that you should have at least more than one node
- Kafka messages are byte arrays. It means that you can store message in any format: string, Marshal or JSON
- Heroku is launching a beta support for Kafka!
- Terence made a sample app that accepts Heroku logs from logdrains and pushed them to Kafka: hone/heroku-replay-ratpack
- Examples of Kafka usecases:
- Heroku billing consumes events about your app to watch when you scale a dyno
- Heroku metrics are built on Kafka too
- Shopify is using Kafka to process all logs from Rails instances
Inside ActiveJob by Jerry D’Antonio
- Right in the talk Jerry built a simple async backend for ActiveJob in just 40 lines of code. This backend is fully functional, and it’s using process memory for the jobs queue instead of Redis as a classical queue.
- The job backend is based on two primitives from concurrent-ruby gem: CachedThreadPool and ScheduledTask. As for me, it the most interesting part because Jerry is the author of concurrent-ruby and he knows a lot about concurrency.
- Read more about internals: thread pools, CachedThreadPool, ScheduledTask
The Rails Boot Process by Xavier Noria
Sometimes you use Rails components independently - as I’d use ActiveRecord in a Sinatra app. In this case, you see exact code that loads them.
But in the case of Rails app, you have no idea how all components are loaded. Xavier explained how it works.
- There are two core files in every Rails project:
config/environment.rb. The first one is loaded at the very beginning. The second one works as a config finalizer and it’s invoked after all other files in
- Every gem that integrates with Rails has a thing called Railtie: it’s a class with a DSL to hook into Rails
- When you subclass from Railtie, a hook is created
Rails.application.initialize! is called, all hooks will be triggered
- See example Railtie from FactoryGirl
3x Rails: Tuning the Framework Internals by Akira Matsuda
- According to Akira’s benchmarks, GC adds about 10% of overhead and it’s not what makes Rails stack slow
- Use rblineprof to profile Ruby scripts
- Ruby has a Tracepoint API. Use it for counting number of method calls
- ActionView paths resolver (when you call
render ‘something, we need to figure out which file is that) has some room for optimization: more_optimized_resolver
- ActionView Multi Encoding support makes rendering very slow. It can be made 1.5x faster by omitting the encoding operations.
- You can already use faster rendering with HAML:
- We can make ActiveSupport::SafeBuffer faster by implementing it in C, as we did with
present? on ActiveRecord models is very slow. You should avoid it
- database_rewinder gem provides faster way to clean DB in test environment
Precompiling Ruby scripts - Myth and Fact by Koichi Sasada
- JIT: planned for Ruby 3
- Ruby 3: Matz wants to release it before Tokyo Olympics in 2020
- Koichi developed an API in Ruby 2.3 for serializing and deserializing bytecode. It allows to skip bytecode step every time when you execute Ruby script. This technique is called Ahead-of-time compilation.
- The API allows you to store serialized bytecode anywhere: in the same directory as ruby script, in specific directory or in database
- yomikomu gem is a demonstration of how it can be used
Turbolinks 5: I Can’t Believe It’s Not Native! by Sam Stephenson
- Turbolinks 5 allows you to build hybrid mobile apps with Rails.
- It comes as a library for Rails, iOS and Android
- You can even use it from NPM with webpack
- Sam demonstrated a video of creating a sample app (not published online yet)
- More: turbolinks-android, turbolinks-ios
This year we had two talks about Sprockets, both from core project developers. These two talks were called “sprocketsconf” and I’ve decided to summarize them as a one.
How Sprockets works by Rafael França,
Saving Sprockets by Richard Schneeman
- What we call Asset Pipeline in Rails is backed by several gems: sprockets, sprockets-rails, sass-rails, execjs, coffee-rails
- As a new maintainer, Richard had to deal with a lot of issues in Sprockets. 70% of project were written by initial author, who no longer could maintain the gem
- Richard wrote Sprockets guides
- Source maps support: it’s not there yet but you can read more in a guide
- If you got 5 minutes a day to check Instagram or Twitter, you’ll find time to maintain your open source projects
- Method docs are like unit tests, but they get outdated
- Deprecation messages as code comments are a bad idea
- Two resources to help you write better code: Practical Object-Oriented Design in Ruby and Exercism.io
RSpec and Rails 5 by Justin Searls
- Most important: Rails 5 drops functional tests. You can use rails-controller-testing gem if you still want to use it
- There is no official way to test ActionCable yet
- rspec-rails providers many ways to test your app: controller, request, feature, view, routing and helper specs. However Justin’s approach is to only use functional and unit (model) test.
- Number of Ruby jobs is dropping last years. Why? Because it’s easy to support and advocate for popular and growing technology. People only share new things. We should understand that it is ok for software to be complete. Ruby has became mature.
Turbo Rails with Rust by Godfrey Chan
- Right now we have 2 opposite directions to write performant code in Ruby. Ruby is slow, and when it comes to C extensions they are dangerous. It’s very easy to get a SEGFAULT.
- In contract, Rust compiler finds errors that may crash in runtime and validates your code from many perspectives
- Rustbridge is a project about making Rust accessible from another platforms
- Godfrey Chan and Yehuda Katz are working on helix, a tool that allows you to write Ruby classes in Rust without having to write the glue code yourself.
Developing and maintaining a platform with Rails and Lotus by Simone Carletti
Confreaks will be posting individual videos for each session in the next weeks. Meanwhile, you already can watch all keynotes:
Google Cloud Platform launches Ruby support: blog post,
Sandi Metz and Katrina Owen are working on a new book about Object Oriented design. Sign up for it
Where Rails will be next year
Looking at the talks content, we can try to predict what new features in Rails and Ruby we will have next year.
We will mostly likely see built-in support for precompiling Ruby in Rails. We will also be able to benefit from embedding language like Rust into our Ruby code. There is even a chance that some of the core Rails components, like ActiveSupport, will have an alternative implementation in Rust.