June 6th, 2012 0 comments

An interesting problem came up today.

One of our models is serializing an arbitrary hash.

This was all well and good until we started looking at runtimes in our controller actions. 34% of runtime was spent parsing YAML.

Experimenting a little, I ran the following test which revealed that JSON.load is two orders of magnitude faster than YAML.load at simple hashes.

This was a shocking result to me, but as I thought about it I realized that YAML exists to store more than just simple hashes, whereas that is all that JSON can do.

It would seem that switching data over from the default YAML to JSON is quite simple.

The problem comes when you have existing data YAML encoded.

I fixed this with a rake task which creates a fake model to avoid other model configurations, validations and automagics and simple parses the YAML and encodes it to JSON. It may not be necessary to create the fake model in the general case, however in my situation where my model is very complicated and doing many different things it was easier to simply eliminate everything.

August 7th, 2011 0 comments

I've been installing Ubuntu 11.04 at last. Unfortunately, rvm choked up. It claimed to install properly, but choked when trying to do the simplest gem commands.

ERROR:  Loading command: install (LoadError)
    no such file to load -- zlib
ERROR:  While executing gem ... (NameError)
    uninitialized constant Gem::Commands::InstallCommand

The solution was hidden in some comments in stack overflow.

rvm pkg install zlib
rvm uninstall 1.8.7 #this can be 1.9.2 or ree, whatever
rvm install 1.8.7 --with-zlib-dir=$rvm_path/usr


May 29th, 2011 0 comments

The Conundrum:

On my current Rails application, I was faced with solving a specific problem: how do I use Paperclip to store many files generated by a single processor without being able to predict how many files there will be or what their names will be. ... (continued)