Forum: Ruby Ruby on Rails: serialize Hash incredibly slow

Posted by Ruben S. (ruben_s)
on 2012-11-09 11:56
(cross post from
http://stackoverflow.com/questions/13292477/ruby-o...,
but I haven't gotten an answer yet)

I've got a simple model called "Search" used for storing searches. It
captures the URL params and stores them in an attribute
:search_criteria, which is serialized as a Hash:

serialize :search_criteria, Hash

This all works perfectly, but it performs horribly. For only 5 objects,
the following statements take roughly 0.2 seconds.

SavedSearch.all.map(&:search_criteria)

If, however, I remove the serialize line (such that search_criteria
returns a string) the statements take only 0.002 seconds. That's 2
orders of magnitude difference for deserializing a Hash!!

What's happening here? I've tried this on multiple systems, including
Heroku, and it's the same everywhere.

Rails.version = 3.2.8

Ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Posted by Ryan Davis (Guest)
on 2012-11-09 19:44
(Received via mailing list)
This list is for ruby, not rails...
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.