[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    Re: CGI.pm - OO syntax vs Function syntax
From:       Stas Bekman <sbekman () iil ! intel ! com>
Date:       1999-09-28 20:52:13
[Download RAW message or body]

> Hi guys,
>
> Sorry if i sound really behind the times here but I was just reading:
> http://stein.cshl.org/WWW/software/CGI/cgi_docs.html#functionvsoo
>
> It says that under modperl using the OO CGI.pm syntax as opposed the the
> qw(:standard) uses somewhat less memory...  I've been using the latter since
> I started with CGI.pm because I didn't like typing $q->  so much.
>
> How much a difference does this really make?  And more important to me,
> *why* does it make that difference?

Aside of namespace pollution, when importing symbols from any module any
script, its size grows by the size of the allocated space for those
symbols. The more you import (e.g. qw(:standard) vs qw(:all)) the more
memory will be used. Let's say the overhead is of size X. Now take the
number of scripts you deploy the function method interface, let's call it
Y. Finally let's say that you have Z number of processes.

You will need X*Y*Z size of additional memory, taking X0k, Y, Z0,
we get 100k*10*30 = 30Mb!!! Now you understand the difference.

Now to benchmark this use GTop.pm:

use GTop ();
use CGI ();
print GTop->new->proc_mem($$)->size;

1 949 696
-------------------
use GTop ();
use CGI qw(:standard);
print GTop->new->proc_mem($$)->size;

1 966 080
-------------------
use GTop ();
use CGI qw(:all);
print GTop->new->proc_mem($$)->size;

1 970 176
-------------------
Results:

import symbols	size(bytes)  delta(bytes) relative to ()
--------------------------------------
() 		1949696    	    0
qw(:standard) 	1966080		16384
qw(:all) 	1970176		20480

So in my example above X k => 20K*10*30 = 6Mb

But generally you use more scripts more processes and probably import more
symbols from the additional modules that use deploy.

But, as reported function method is faster in general case, because of the
time overhead to resolve the pointer from the object.

If you are heading to performance improving direction, you will have to
face the fact, that having to type My::Module::my_method might save you a
good chunk of memory if the above call must not be called with a reference
to an object, but even then it can be passed by value.

_______________________________________________________________________
Stas Bekman  mailto:sbekman@iil.intel.com    www.singlesheaven.com/stas
Perl,CGI,Apache,Linux,Web,Java,PC at  www.singlesheaven.com/stas/TULARC
www.apache.org  & www.perl.com  == www.modperl.com  ||  perl.apache.org
single o-> + single o-+ = singlesheaven    http://www.singlesheaven.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic