From: Eric Hodel Date: 2011-03-16T15:24:29+09:00 Subject: Re: NoMethodError#message takes very long On Mar 15, 2011, at 8:25 PM, Adiel Mittmann wrote: > Hello. > > I've been noticing a problem for a while in a larger application and today I > produced a minimal example, given below. When a method is not found, Sinatra > calls NoMethodError#message to display a nice error message, but that is taking > VERY long. > > > require 'sinatra' > require 'nokogiri' > get '/' do > @xml = Nokogiri::XML(File.new('baz.xml', 'rb').read()) > foo() > 'hello' > end > > > The file 'baz.xml' can be just a simple file, like a root element containing > some thousands of elements. The number of elements is important because, oddly > enough, the time taken for the message to be displayed is proportional to the > size of the XML file. In my system, with a 3.7 MB file this program takes almost > 13 seconds to print the message, but in a larger application the message takes a > few minutes to appear. Let me see if I have this straight: If baz.xml is empty it is fast If baz.xml is large it is slow If this is true it is because it takes time to parse the XML file before it gets to foo and discovers that there is no method foo. Ruby does not know that foo does not exist until you try to call it.