Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active December 11, 2015 19:29
Show Gist options
  • Select an option

  • Save henrik/4649195 to your computer and use it in GitHub Desktop.

Select an option

Save henrik/4649195 to your computer and use it in GitHub Desktop.
Got a script using Savon 2 with the e-conomic SOAP API (a 3 MB WSDL) down from around 30 seconds to around 2 seconds by marshalling the Wasabi WSDL parser. Consider this a proof-of-concept.
# For Wasabi 3.0.0.
# Marshals WSDL for a huge speedup with large files.
# A 3 MB WSDL went from around 30 to 2 seconds.
# Marshalling: 3.1 MB -> 629 KB.
# Zipping: 629 KB -> 59 KB.
module Wasabi
class Parser
alias_method :old_parse, :parse
def parse
old_parse
# The Nokogiri document prevents marshalling.
# We've parsed so we don't need the document anymore.
self.document = nil
end
end
class Document
alias_method :old_parser, :parser
def parser
return @parser if @parser
@parser = load_parser_from_marshal
unless @parser
old_parser
dump_parser_to_marshal
end
@parser
end
private
def load_parser_from_marshal
if File.exist?(marshal_file)
Marshal.load(unzip(File.read(marshal_file)))
end
end
def dump_parser_to_marshal
data = zip(Marshal.dump(@parser))
File.open(marshal_file, "w") { |f| f.write(data) }
end
def zip(string)
Zlib::Deflate.deflate(string)
end
def unzip(string)
Zlib::Inflate.inflate(string)
end
def marshal_file
basename = File.basename(@document)
"./#{basename}.marshalled.zip"
end
end
end
@henrik
Copy link
Author

henrik commented Jan 27, 2013

And around 60 KB zipped. If that doesn't slow things down measurably, it could keep the file size down even more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment