svenfuchs/i18n — pull request #178 by mrsimo (2012-11-15 16:13:58+00:00)
Title: Simple json backend leveraging MultiJson

Hi there,
I work in a rather big rails app with a TON of translations. We have an app that translators translate the keys, and then we export them into yml files with an internal rest api.

We're also migrating to ruby 1.9, and faced a tremendous performance hit with the new Psych parser. For instance:

1.8.7 $ be rails runner "puts Benchmark.measure { I18n.t :asdasdasd }"
2.740000 0.080000 2.820000 ( 2.822331)

1.9.3 $ be rails runner "puts Benchmark.measure { I18n.t :asdasdasd }"
8.730000 0.170000 8.900000 ( 8.924644)

I did a quick experiment, and turns out any modern json parser is a lot more efficient. With this pull request:

1.9.3 $ be rails runner "puts Benchmark.measure { I18n.t :asdasdasd }"
0.950000 0.050000 1.000000 ( 0.995695)

I'm talking about 250k lines of yml files. This is with the Oj gem as backend for MultiJson.

I went for a new backend, but to be honest, the changes are so tiny that if you find it interesting I think we could add the load_json method to the simple backend.

I'm leveraging MultiJson instead of ActiveSupport::JSON (used on the KeyValue backend)... please also comment what you think. Doesn't make too much sense pulling ActiveSupport for such a tiny task.

Cheers!