Slim-Attributes v0.5.0 released
I just released a new version of slim-attributes. There are some small speed gains and some other minor changes from 0.4.1, but there are no big changes.
Read more about slim-attributes at the slim-attributes homepage, or read on below.
Introduction
Slim-attributes is a small patch to the ActiveRecord Mysql adaptor that stops rails from immediately making ruby strings from the column names and data from your database queries. Because you probably don't need them all!
So ruby strings are lazily created on demand - it's faster and uses less memory. And it drops directly in, requiring only the installation of a gem and adding 1 line to environment.rb.
Measuring with just ActiveRecord code - fetching stuff from the database - we see anything up to a 50% (or more) speed increase, but it really depends on your system and environment, and what you are doing with the results from the database. The more columns your tables have, the better the improvement will likely be. Measure your own system and send me the results!
Installation
Try:
or:
then add this to environment.rb:
Description
Normally the mysql adaptor in Rails returns a hash of the data returned from the database, one hash per active record object returned by the query. The routine that generates these hashes is called all_hashes, and this is what we replace. The reason for overriding all_hashes is threefold:
gem install slim-attributes -- --with-mysql-config
gem install slim-attributes
require 'slim_attributes'
- making a hash of each and every row returned from the database is slow
- rails makes frozen copies of each column name string (for the keys) which results in a great many strings which are not really needed
- we observe that it's not often that all the fields of rows fetched from the database are actually used