Hello,
the current version of NDB stores Array/Hash/GeneralRubyObjects using
the Marshal.dump/load methods. This is relatively fast but not portable.
Ie it is difficult to use the database from an application coded in
another language due to Marshal being Ruby specific.
I could use yaml of course but I am wondering if this is fast enough.
Any opinions on this?
That depends upon what you consider fast enough?
If you read the Ruby-Talk thread starting at [99960] you can see some
benchmarks.
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/99960
REXML.
But, you need to watch out about what you store as YAML. If you are
only just storing Arrays and Hashes of Strings, Numbers and other such
things you are probably fine, but as soon as custom Ruby Objects start
appearing you may be in trouble.
I have learned this the hard way, when working with objects that
dynamically extend modules. Attached is a simple example of an
interesting difference between Marshal and YAML, with regards to
saving an objects state.
I hope this helps.
Best,
Zev
···
On Wed, 27 Oct 2004 21:09:06 +0900, George Moschovitis <gm@navel.gr> wrote:
From my experience YAML is much faster than an XML equivalent using
-----
Example code that shows that Marshal can store the modules extended
by a specific object, while YAML cannot.
-----
module TestModule
def foo
puts "bar!"
end
end
x = "String"
x.extend TestModule
puts "Is x a TestModule?"
puts x.is_a?(TestModule)
y = "String y"
puts "Is y a TestModule?"
puts y.is_a?(TestModule)
include Marshal
puts "Dumping and Reloading X"
rx = restore(dump(x))
puts "Is the reloaded X a TestModule?"
puts rx.is_a?(TestModule)
puts "Just to make sure we can still foo."
puts rx.foo
puts "Dumping and Reloading Y (for fun)."
ry = restore(dump(y))
puts "Is the reloaded Y a TestModule? (I hope not.)"
puts ry.is_a?(TestModule)
puts "Now let's try the equivalent in YAML"
require "yaml"
yx = YAML.load(x.to_yaml)
puts "Is the YAML reloaded X a TestModule?"
puts yx.is_a?(TestModule)