[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

CGI::Cookie destroys performance by using SimpleDelegator

David Heinemeier Hansson

10/23/2004 10:59:00 PM

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.c...
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.basec... -- Web-based Project Management
http://www.rubyon... -- Web-application framework for Ruby
http://macro... -- TextMate: Code and markup editor (OS X)
http://www.loudthi... -- Broadcasting Brain



3 Answers

George Moschovitis

10/24/2004 7:33:00 AM

0

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

George.

Yukihiro Matsumoto

10/24/2004 10:37:00 AM

0

Hi,

In message "Re: CGI::Cookie destroys performance by using SimpleDelegator"
on Sun, 24 Oct 2004 07:59:19 +0900, David Heinemeier Hansson <david@loudthinking.com> writes:

|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.c...
|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.


David Heinemeier Hansson

10/24/2004 10:48:00 AM

0

> 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.basec... -- Web-based Project Management
http://www.rubyon... -- Web-application framework for Ruby
http://macro... -- TextMate: Code and markup editor (OS X)
http://www.loudthi... -- Broadcasting Brain