Fast Bulk Record Updates in Rails

Today I investigated a performance issue in a client’s Rails application. The problem code was taking about 40 seconds to create and/or update several thousand database records, resulting in HTTP request timeouts. After taking some measurements, reorganizing the code a bit, and applying some standard optimizations, that went down to 8 seconds. A 5× speed boost isn’t bad, and the client would…