I think, yes, denying the importance of using slimmer and faster variants of certain common tools/modules is not the wisest thing to do. For one, I already see quite a number of CGI scripts that which require performance boost and one way I might do it is by simply converting from 'use CGI' to 'use CGI::Simple;'. This will be especially easy to do since most of my CGI scripts don't require extended features supplied with standard CGI module.
However, as far as 'extended' features go, is it not true that CGI doesn't really load them until they are first requested inside the main code? Basically, CGI keeps this
%SUBS hash which contains a whole bunch of subroutines' definitions. These are loaded only on the first time each one is requested. I feel like author(s) of the modules eagerly tried to drive this point across with this comment (ripped from CGI.pm):
######################################################################
+#########
################# THESE FUNCTIONS ARE AUTOLOADED ON DEMAND ###########
+#########
######################################################################
+#########
This is followed by the infamous %SUBS hash:
%SUBS = (
'read_from_client' => <<'END_OF_FUNC',
# Read data from a file handle
sub read_from_client {
my($self, $fh, $buff, $len, $offset) = @_;
local $^W=0; # prevent a warning
return undef unless defined($fh);
return read($fh, $$buff, $len, $offset);
}
END_OF_FUNC
### MANY OTHER EXCITING SUBS ###
);
So, say, even if I went the 'use CGI;' way, the only time wasted here
(provided I have no interest in making a call to the CGI::read_from_client() method)
is that required for the hash to load. Perl parser wouldn't waste a nanosecond
on parsing the actual sub. This is a huge time saver compared to if
subs were not nicely hidden inside a hash etc. (the standard way).
I'm wondering if this would explain the fact that CGI::Simple is only
50% faster than CGI?
"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith
|
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.