serialization

An article by Gaspard Bucher
  1. action
  2. ajax
  3. API
    1. zafu
    2. query builder
    3. rubyless
    4. gold
    5. property
    6. versions
    7. remote
    8. zazen
    9. console
  4. classes
  5. common attributes
  6. conditions
  7. context
  8. dates
  9. display
  10. forms
  11. i18n
  12. meta
  13. SQLiss
  14. urls


After intensive testing of YAML, Marshal and JSON serialization (all available and tested in the gem), we have decided to use JSON because it’s the fastest solution in real-world cases and it’s less problematic on the long run.

In case you have read that Marshal is faster then JSON, this might be the case if:

  • you don’t read (decode) more often then you encode (not the case in a web app)
  • the tests don’t include the ‘pack’ and ‘unpack’ necessary to move the data in the database

My own benchmarks show:

         user       system     total       real
JSON     0.710000   0.010000   0.720000 (  0.720144)
Marshal  0.830000   0.050000   0.880000 (  0.888717)

You can download the “testfile” if you want.

PS: In fact, Marshal is faster if you encode lots of tiny objects, but there are many disadvantages to using Marshal encoding that the tiny speed difference is just not worth it.