D
Derek Fountain
I've inherited a piece of code that does something like this:
sub func {
my %hash = ();
...lots of code that populates and uses the hash
%hash = ();
}
There are hundreds of these functions and they are called millions of
times in a procedure which takes hours, sometimes days, to complete. The
guy who wrote it was obviously concerned about performance.
The question pertains to that resetting of the hash at the end of
function. Does it do anything that exiting the function doesn't do? In
Java-land I've seen things like that to force the garbage collector to
jump in, but in Perl-land won't it just get optimised away? The hash
doesn't get that big, as far as I can see, and there's nothing unusual
in any of the hash processing code.
Normally I'd just remove the line (or ignore it) but since it appears in
every one of these functions, and since removing a useful optimisation
might add an hour or two to my runtime, I thought I'd ask.
sub func {
my %hash = ();
...lots of code that populates and uses the hash
%hash = ();
}
There are hundreds of these functions and they are called millions of
times in a procedure which takes hours, sometimes days, to complete. The
guy who wrote it was obviously concerned about performance.
The question pertains to that resetting of the hash at the end of
function. Does it do anything that exiting the function doesn't do? In
Java-land I've seen things like that to force the garbage collector to
jump in, but in Perl-land won't it just get optimised away? The hash
doesn't get that big, as far as I can see, and there's nothing unusual
in any of the hash processing code.
Normally I'd just remove the line (or ignore it) but since it appears in
every one of these functions, and since removing a useful optimisation
might add an hour or two to my runtime, I thought I'd ask.