Syckle

3 views
Skip to first unread message

Simon Chiang

unread,
Jan 8, 2009, 2:26:47 PM1/8/09
to Zaml
Hey everyone,

This doesn't directly affect ZAML, but as a followup to some of the
work I was doing to get YAML to require quicker, I though I'd let you
know about Syckle. Turns out YAML requires slowly in large part
because it requires 'date'. I found I could make a tiny binding to
syck that loads basic types (true, false, nil, numbers, strings,
symbols, arrays, hashes) as fast as YAML, and requires at least 10x
faster. When Syckle.load runs into a type it can't handle, it
requires YAML in full and defers to YAML.load.

Syckle is a nice as an experiment, and useful for scripts that only
need YAML to load (say) a config file. In that case the script launch
time will be reduced.

http://github.com/bahuvrihi/syckle/tree/master
http://bahuvrihi.github.com/syckle/

What may be interesting wrt ZAML is that making a syck binding really
is easy. Maybe one of the reasons YAML is slow to dump is that some
of the to_yaml methods are not optimized. This is the
String.to_yaml...
you can see every string dump requires quite a bit (comments added by
me):

def to_yaml_style; end

def to_yaml_properties; instance_variables.sort; end

def is_complex_yaml?
# a regexp match across the whole string
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.
+/
end

def is_binary_data?
# two counts of the whole string
( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count
( "\x00" ) > 0 ) unless empty?
end

def to_yaml( opts = {} )
YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
if is_binary_data?
out.scalar( "tag:yaml.org,2002:binary", [self].pack
("m"), :literal )
elsif to_yaml_properties.empty?

# the majority of strings go here, I think...
out.scalar( taguri, self, self =~ /^:/ ? :quote2 :
to_yaml_style )
else
out.map( taguri, to_yaml_style ) do |map|

# this is an outright copy of the string right?
map.add( 'str', "#{self}" )
to_yaml_properties.each do |m|
map.add( m, instance_variable_get( m ) )
end
end
end
end
end

May or may not be worth anything, but has anyone checked if YAML could
be sped up on this level?

- Simon
Reply all
Reply to author
Forward
0 new messages