CGI::Cookie destroys performance by using SimpleDelegator

  • Thread starter David Heinemeier Hansson
  • Start date
D

David Heinemeier Hansson

Just like Tempfile, CGI::Cookie uses SimpleDelegator. This causes a
massive performance overhead for mod_ruby/FCGI based sites. I did a
profile on 50 requests through a simple Rails that recorded 26,000
calls to String.===, which SimpleDelegator was responsible for.

The fix is exactly the same as what Matz recommended for Tempfile in:
http://groups.google.com/groups?
th=e3a4e68ba042f842&seekm=c3sioe%241qvm%241%40news.cybercity.dk#link14

-class CGI::Cookie < SimpleDelegator
+class CGI::Cookie < DelegateClass(Array)

+ def __setobj__(obj)
+ @_dc_obj = obj
+ end

I hope this change can make it into Ruby 1.8.2. For now, Rails (0.8)
will include a custom CGI::Cookie with these changes. The fixed version
gives about 100% more performance on some cases.
--
David Heinemeier Hansson,
http://www.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://macromates.com/ -- TextMate: Code and markup editor (OS X)
http://www.loudthinking.com/ -- Broadcasting Brain
 
G

George Moschovitis

Wow this is interesting, and I ve missed the initial post about
Tempfile.
Thanks for the info.

George.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: CGI::Cookie destroys performance by using SimpleDelegator"

|Just like Tempfile, CGI::Cookie uses SimpleDelegator. This causes a
|massive performance overhead for mod_ruby/FCGI based sites. I did a
|profile on 50 requests through a simple Rails that recorded 26,000
|calls to String.===, which SimpleDelegator was responsible for.
|
|The fix is exactly the same as what Matz recommended for Tempfile in:
|http://groups.google.com/groups?
|th=e3a4e68ba042f842&seekm=c3sioe%241qvm%241%40news.cybercity.dk#link14

Point taken. I will merge your fix. By the way, I think your
__setobj__ method is not required. Are there any reason to redefine
it in cgi.rb?

matz.
 
D

David Heinemeier Hansson

Point taken. I will merge your fix. By the way, I think your
__setobj__ method is not required. Are there any reason to redefine
it in cgi.rb?

Not really, I was just following your lead in the Tempfile fix. If it's
not needed the fix is even simpler ;)

I just grep'ed through the standard library and found this as well:

/usr/local/lib/ruby/1.8/net/telnet.rb: class Telnet < SimpleDelegator

Might be worth investigating whether Telnet should also switch away
from SimpleDelegator.

Anyway, thanks a lot for the quick response, Matz. I'll be able to pull
the CGI::Cookie redefinition from Rails shortly it sounds :)
--
David Heinemeier Hansson,
http://www.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://macromates.com/ -- TextMate: Code and markup editor (OS X)
http://www.loudthinking.com/ -- Broadcasting Brain
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top