Ruby, Rails, Firefox, Anime, Mac
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.
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).
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.
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
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
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 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
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.
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
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][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
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.