This talk is about optimizing your ruby and rails code. It focuses on the basics. Too many times people focus on using fun tools. Before you attack the fun stuff you should tackle the low hanging fruit. ror-e.com
28. Take a look at the RailsCast http://railscasts.com/episodes/181-include-vs-joins Use includes if you need to use the method on the associated model Use joins if you need to filter the objects loaded by SQL.
35. Know your API If you are doing something that you think should be part of ruby. It probably is. inject map join compact uniq DON’T RECREATE THESE METHODS (maybe inject but….)
36. INJECT SUCKS when…. object.inject({}) do |h, new_h| new_h[h.id] = h.some_method new_h end new_array = Object.map do |obj| [obj.id , obj.some_method] end Hash[new_array]
38. Class SomeController < ActionController::Base def edit @post = Post.find(id) form_info end def update @post = Post.find(id) if @post.update_attributes(params[:post]) redirect_to :action => :index else form_info render :edit end end end private defform_info @states = State.find(:all).map{|s| [s.name, s.id]} end end
45. You need to make sure that your Gemfile specifies that the ruby-debug19 gem is available in both the test and development environments by specifying it using group :test, :development in the Gemfile
61. Set the value to about 2.5Gig less than your system RAM If you share your DB with memcached or passenger or anything else you need to set this value to have less RAM
69. Index the first 10 charactersexecute('CREATE INDEX users_last_name_ten ON users (last_name(8));') execute('CREATE UNIQUE INDEX users_email_ten ON users (email(10));')
78. Jammitvs Asset Packager Both work. I like Jammit. Asset Packager works on Heroku http://www.viget.com/extend/static-asset-packaging-rails-3-heroku/
81. Counter Cache Great when you do things like: User.groups.size This value would be stored in the users table. http://railscasts.com/episodes/23-counter-cache-column
83. Background Processes Delayed Job resque Workling & Starling Rabbit MQ Lot of tasks don’t need to be real time. Give your users inboxes or emails with tokens to receive the info. Example: PDF generation, reports, cleanup of your cart.
84. COOL STUFF MemProf NewRelic Memcached Combine your SQL DB with noSQL
My name is David Henner, and today I’ll talk about optimizing the obvious.
This is my web site, twitter, github, and you can contact me at drhenner@rorecommerce.com
Ask question and listen. Memcached, noSQL, memprof.Tell them about a project manager you had that thought it was adding a lot more functionality to one page. More glitter, and bells and whistles.
Paperclip does no optimize images after they are re-sized. Make sure your images are optimized for each size.
This is my web site, twitter, github, and you can contact me at drhenner@rorecommerce.com