You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Nigel Hamilton <ni...@turbo10.com> on 2003/07/07 17:50:50 UTC

Apache::Registry -> String Compaction == Less RAM?

Hi,
	Apache::Registry slurps in your Perl modules as strings and 
then evals them.

	I thought I could save some RAM by stripping out comments and
whitespace before the eval step - so I quickly wrote a Registry-like
handler that strips comments.

	Alas, the experiment failed - I saw no difference in RAM usage at 
all! 

	I suspect that mod_perl is stripping them for me. But isn't a
large string allocated in RAM prior to the eval?

	Are there any merits in a comment stripping pre-processing step 
in a Registry-like handler?	


NIge

-- 
Nigel Hamilton
Turbo10 Metasearch Engine

email:	nigel@turbo10.com
tel:	+44 (0) 207 987 5460
fax:	+44 (0) 207 987 5468
________________________________________________________________________________
http://turbo10.com		Search Deeper. Browse Faster.


Re: Apache::Registry -> String Compaction == Less RAM?

Posted by Stas Bekman <st...@stason.org>.
[sent it out too early]

Stas Bekman wrote:
> Also see:

http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlResponseHandler


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Apache::Registry -> String Compaction == Less RAM?

Posted by Stas Bekman <st...@stason.org>.
Perrin Harkins wrote:
> On Mon, 2003-07-07 at 11:50, Nigel Hamilton wrote:
> 
>>	I thought I could save some RAM by stripping out comments and
>>whitespace before the eval step - so I quickly wrote a Registry-like
>>handler that strips comments.
> 
> 
> Those don't take up any space in the actual compiled opcodes.  The only
> space you could save is in the string that the file is initially loaded
> into and the $eval string that gets built up to pass to eval().

[...]

I'd just like to add an example which shows you what exactly perl sees when it 
compiles your code:

perl -MO=Deparse -le '\
print \
"this is a string" \
# hmm, some comment \
. "another string" \
# bummer, i should end the line now \
;'

prints:

BEGIN { $/ = "\n"; $\ = "\n"; }
print 'this is a stringanother string';
-e syntax OK

Also see:


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Apache::Registry -> String Compaction == Less RAM?

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2003-07-07 at 11:50, Nigel Hamilton wrote:
> 	I thought I could save some RAM by stripping out comments and
> whitespace before the eval step - so I quickly wrote a Registry-like
> handler that strips comments.

Those don't take up any space in the actual compiled opcodes.  The only
space you could save is in the string that the file is initially loaded
into and the $eval string that gets built up to pass to eval().

It's probably not worth pursuing, since the savings would be small and
there is a risk of breaking code (parsing perl is hard).  If you want to
see how much it could possibly save, try just stripping a single file
before feeding it to Registry and see how much of a difference that
makes.

> 	I suspect that mod_perl is stripping them for me.

Nope, it doesn't do anything like that.

>  But isn't a
> large string allocated in RAM prior to the eval?

Yes, the $eval string is as large as the full contents of the file.

- Perrin