Someone has asked how to check the compiled size of subs and vars in
mod_perl. New Apache::Status does it for you. There are many new features
in the new Apache::Status, this post covers only the 'Memory Usage'
feature.
Apparently it's a very easy task.
Installation:
* grab the latest CVS snaphost of mod_perl (you need the latest
Apache::Status module) perl.apache.org/from-cvs/modperl
* build mod_perl
* install B::TerseSize
Configuration:
* Configure /perl-status if you didn't before, e.g:
Location /perl-status
SetHandler perl-script
PerlHandler Apache::Status
order deny,allow
#deny from all
#allow from ...
/Location
* Add to httpd.conf
PerlSetVar StatusOptionsAll On
PerlSetVar StatusTerse On
PerlSetVar StatusTerseSize On
PerlSetVar StatusTerseSizeMainSummary On
* start the server (best in httpd -X mode)
Usage:
From your favorite Netscape browser
* fetch http://localhost/perl-status
* clock on 'Loaded Modules' or 'Compiled Registry Scripts'
* click on module or script of your choice (you might need to run some
script/handler before you will see it here unless it was preloaded)
* click on 'Memory Usage' at the bottom
* Now you will see all the variables and subs and their sizes. Note (you
might have to reload it a few times, at least it failed for me every 2nd
reload).
Now you can start to optimize your code, or choose one of the 2 versions.
To show you how you can help yourself let's prepare 2 script one
For example let's compare OO vs methods CGI.pm's interfaces:
As you will see below the first OO script uses about 2k bytes while the
second script (methods interface) uses about 18k. I'm not trying to prove
a thing, just bringing an example so please no protest is required :)
Here are the code and the numbers:
Code:
1)
use CGI ();
my $q = new CGI;
print $q-header;
print $q-b("Hello");
2)
use CGI qw(:standard);
print header();
print b("Hello");
Sizes:
1)
Totals: 1966 bytes | 27 OPs
handler 1514 bytes | 27 OPs
exit 116 bytes | 0 OPs
2)
Totals: 17969 bytes | 19 OPs
handler 1117 bytes | 19 OPs
start_multipart_form 132 bytes | 0 OPs
use_named_parameters 132 bytes | 0 OPs
end_multipart_form130 bytes | 0 OPs
restore_parameters130 bytes | 0 OPs
server_software 127 bytes | 0 OPs
server_protocol 127 bytes | 0 OPs
path_translated 127 bytes | 0 OPs
save_parameters 127 bytes | 0 OPs
scrolling_list126 bytes | 0 OPs
request_method126 bytes | 0 OPs
password_field126 bytes | 0 OPs
checkbox_group126 bytes | 0 OPs
query_string 124 bytes | 0 OPs
import_names 124 bytes | 0 OPs
virtual_host 124 bytes | 0 OPs
remote_ident 124 bytes | 0 OPs
content_type 124 bytes | 0 OPs
image_button 124 bytes | 0 OPs
remote_addr 123 bytes | 0 OPs
remote_host 123 bytes | 0 OPs
URL_ENCODED 123 bytes | 0 OPs
tmpFileName 123 bytes | 0 OPs
server_port 123 bytes | 0 OPs
param_fetch 123 bytes | 0 OPs
radio_group 123 bytes | 0 OPs
server_name 123 bytes | 0 OPs
script_name 123 bytes | 0 OPs
remote_user 123 bytes | 0 OPs
uploadInfo122 bytes | 0 OPs
start_html122 bytes | 0 OPs
autoEscape122 bytes | 0 OPs
start_form122 bytes | 0 OPs
user_agent122 bytes | 0 OPs
raw_cookie122 bytes | 0 OPs
Delete_all122 bytes | 0 OPs
blockquote122 bytes | 0 OPs
popup_menu122 bytes | 0 OPs
url_param 121 bytes | 0 OPs
user_name 121 bytes | 0 OPs
MULTIPART 121 bytes | 0 OPs
startform 121 bytes | 0 OPs
cgi_error 121 bytes | 0 OPs
auth_type 121 bytes | 0 OPs
path_info 121 bytes | 0 OPs
filefield 121 bytes | 0 OPs
textfield 121 bytes | 0 OPs
textarea 120 bytes | 0 OPs
basefont 120 bytes | 0 OPs
checkbox 120 bytes | 0 OPs
redirect 120 bytes | 0 OPs
defaults 120 bytes | 0 OPs
end_html 120 bytes | 0 OPs
frameset 120 bytes | 0 OPs
end_form 120 bytes | 0 OPs
self_url 120 bytes | 0 OPs
endform 119 bytes | 0 OPs
comment 119 bytes | 0 OPs
referer 119 bytes | 0 OPs
isindex 119 bytes | 0 OPs
caption 119 bytes | 0 OPs
address 119 bytes | 0 OPs
Accept118 bytes | 0 OPs
upload118 bytes | 0 OPs
hidden118 bytes | 0 OPs
strike118 bytes | 0 OPs
Delete118 bytes | 0 OPs
submit118 bytes | 0 OPs
button118 bytes | 0 OPs
Select118 bytes | 0 OPs
ilayer118 bytes | 0 OPs
header118 bytes | 0 OPs