develooper Front page | perl.perl5.porters | Postings from February 2004

Re: [perl #26188] undef speedup ?!

Thread Next
From:
Alex Efros
Date:
February 9, 2004 01:52
Subject:
Re: [perl #26188] undef speedup ?!
Message ID:
20040209041057.GA8994@home.power
Hi!

On Mon, Feb 09, 2004 at 03:32:50AM -0000, Michael G Schwern via RT wrote:
> With a defined hash, keys() must look at the hash structure and determine
> how many keys there are.  Additionally it must reset the iterator for
> each().  With an undefined hash, it just returns an empty list without
> doing any extra work.  So keys() is simply optimized when a hash is 
> undefined.
> 
> That doesn't seem right at all.  Devel::Peek shows that the keys are
> indeed deleted and the hash is aware that it has 0 keys.

Devel::Peek return:
(after delete @hash{keys @hash})
    ARRAY = 0x40376008
    KEYS = 0
(and after undef %hash)
    ARRAY = 0x0
    KEYS = 0
So, I think it would be very nice and simple optimization if keys() will
check KEYS before ARRAY and if KEYS=0 then do nothing.

...I've some very optimized long-running scripts which do a lot of work and
consume a lot of CPU, and noticed some slowdown after working a couple
of hours... I've checked these scripts very carefully, but not found
anything which may slowdown the script... Now I start thinking what
source of this slowdown may be in such keys() operations, and I will try
to undef() hashes or copy main hash to temporary, undef main hash and
copy temporary to main again from time to time while script is working...

-- 
			WBR, Alex.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About