|Problems? Is your data what you think it is?|
Not returning scalars(SV) to optimize and save memory?by Withigo (Friar)
|on Dec 06, 2007 at 19:52 UTC||Need Help??|
Withigo has asked for the
wisdom of the Perl Monks concerning the following question:
I have a question about how Perl internally works when returning from subroutines. I'm in a debate about whether it is a meaningful optimization to not use "return" and "return 1" in subroutines. What has been instead been proposed is to do something like this:
Let's say foo() and bar() are called millions of times. The claim is the foo() is creating a new scalar (SV) upon each call and returning it, and that bar() is not making perl internally use more memory/cpu resources than it already has allocated. The claim is that perl does something magical with the result of '1 == 1' and '1 == 0', and does not create a new SV to represent the result of that operation.
However, I would think that something so fundamental as the simple return values from subs would already be optimized internally so as to not add needless overhead.
Can anyone confirm any of this?