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