Living on the edge (of Rails) #6 – better performance, Git support, and more

In: Edge Rails|Open Source|Ruby|Ruby on Rails

6 Feb 2008

Here’s another week of noteworthy updates on the Rails trunk. Thanks once again to the Rails Envy podcast for featuring my updates, and even bigger thanks to the Rails contributors and committers who make things happen. This week’s Living on the Edge was covered in Rails Envy podcast #17.

The company I work for, Bezurk (yeah we know some of you hate the name “Bezurk” – that’s going to change), is currently looking for a Ruby developer to join our ranks. This person will be working mainly on Ruby-based web development projects. As we all know, “Rails doesn’t scale” (delivered in Jason Seifer-style – meaning it’s just a joke!) so we’d love anyone who’s up for a challenge and who’s also willing to work outside the Rails comfort zone (our current favorite: Ramaze). Our Ruby team currently comprises 3 experienced developers and 1 up and coming Rubyist.

We’re active Open Source contributors (Arun released ActiveCouch recently), while I am a Rails contributor (I’m ‘chuyeow’ on the Rails Trac) myself.

If all this sounds interesting enough to you, do check out the full job description and drop us an email. Yes, we’re serious when we said “+1 for DotA/Counterstrike skills)”. There’s a catch though – you have to work on location at our office in Singapore.

Anyway, let’s get back on topic – this weeks’ report covers changes from 28 Jan 2008 to 3 Feb 2008 (the day the Rails Envy podcast was recorded).

Saving, creating and updating ActiveRecord objects is more efficient

Thanks to Gleb Arshinov and Alexander Dymo with their blog post and patches about improving Rails performance by approaching it via minimizing garbage collection, saving, creating, and updating ActiveRecord objects is now significantly more efficient.

The expensive ActiveRecord::Base#attributes method is no longer called internally, so there’s no unnecessary cloning of attribute values. Less memory usage means less garbage collection, which means better performance!

Related changeset: http://dev.rubyonrails.org/changeset/8770

SQL calls and rendering are faster

This patch is courtesy of Gleb Arshinov and Alexander Dymo too.

Rails surrounds every SQL call and ActionView::Base#render with the ruby method Benchmark#realtime so that it can print out some benchmarking numbers. Benchmark#realtime allocates an unnecessary 45k of memory per call (who knew!). This has been monkey patched in Rails to a leaner implementation, reducing memory usage and increasing performance.

Related changeset: http://dev.rubyonrails.org/changeset/8771

MySQL adapter slight optimization

Table and column names in the MySQL adapter are now cached in instance variables, reducing memory allocations (and thus the need for GC).

Related changeset: http://dev.rubyonrails.org/changeset/8794

script/generate does Git!

script/generate now allows you to pass the ‘–git’ (or ‘-g’) option to add the generated files to git (much like how you could do the same with Subversion with ‘-c’ or ‘–svn’). This patch is the work of Steven Soroka so nice work Steven!

Related changeset: http://dev.rubyonrails.org/changeset/8772

map.resources :products, :as => ‘something_else’

Here’s something that will make non-english Rails developers happy: you can now do, for example,

map.resources :comments, :as => 'comentarios'

so that you can keep having your model names independent of what URLs you’d actually like to appear on the site.

The above map.resources means that you can keep your resource and model names in English (Comment), while having URLs like this: /comentarios/123.

Related changeset: http://dev.rubyonrails.org/changeset/8785

:index option for form_for and fields_for to simplify multi-model forms

Inspired by a Railscasts episode where Ryan Bates mentions how ugly it is to have to pass :index => nil to prevent #text_field (and other form helpers) from inserting the model’s ID in the input name (e.g. project[task_attributes][123][name] when what you really want is project[task_attributes][][name]).

Meaning instead of

<% fields_for "project[task_attributes][]", task do |f| %>
  <%= f.text_field :name, :index => nil %>
  <%= f.hidden_field :id, :index => nil %>
<% end %>

you can now do:

<% fields_for "project[task_attributes][]", task, :index => nil do |f| %>
  <%= f.text_field :name %>
  <%= f.hidden_field :id %>
<% end %>

Related changeset: http://dev.rubyonrails.org/changeset/8786

No more emails in your production logs

You’d probably have noticed that ActionMailer logs entire email messages in the log, even in production. Well, it’s been changed to be less verbose now. At the :info log level, only the recipients are logged. You can still see the entire email at the :debug log level (which is the default for development environment).

Related changeset: http://dev.rubyonrails.org/changeset/8781

As always, let me know of any inaccuracies or any suggestions you may have in the comments. Oh, and if you liked this, do me a favor by submitting it to Ruby Reddit.

5 Responses to Living on the edge (of Rails) #6 – better performance, Git support, and more

Avatar

Michael Klishin

February 7th, 2008 at 2am

Nice summary, thanks. Git and m17n love to resources is great. But extra performance is even better. We are one the road to Merb now ;)

Avatar

hemant

February 7th, 2008 at 3am

Quite nice and good luck with finding your Ruby guy!

Avatar

Rails Podcast Brasil - Epis?dio 4

February 7th, 2008 at 8pm

[...] Living on the edge (of Rails) #6 – better performance, Git support, and more [...]

Avatar

A Fresh Cup » Blog Archive » Double Shot #139

February 7th, 2008 at 8pm

[...] Living on the edge (of Rails) #6 – better performance, Git support, and more – The latest news roundup from the cutting edge. [...]

Avatar

Le Vosgien du Net · Rails 2.1, ça roule maintenant ! - Le tutoriel complet - 2ème partie

August 4th, 2008 at 3pm

[...] Redemtion in a Blog a aussi suivi le moindre petit changement dans Rails Edge et je vais lui emprunter les morceaux les plus intéressants. [...]