develooper Front page | perl.perl5.porters | Postings from April 2000

[ID 20000425.006] Slow map - patch + discussion

Thread Next
Ben Tilly
April 25, 2000 12:49
[ID 20000425.006] Slow map - patch + discussion
Message ID:
This is an update on my earlier bug report.  After reading the "This Week on 
P5P" output by Mark-Jason Dominus I felt sheepish for offering complaints 
and no patches.  So here is a full response to everything that appears in:

So an update on my complaints from last week and a patch.

First of all I was exactly right about what was going wrong with map() and I 
am attaching a patch at the end of this emaill.  My patch is not ideal since 
how much you resize the stack should depend upon how many times you have had 
to resize it already.  But it is a significant improvement and perfectly 
solves the common array2hash 2-for-1 map.

Secondly there is a patch in the Changes for 5.6 that solves the missing 
field-names in pseudo-hash warnings.  If there is ever a 5.005_04 I really 
want that change in there.  (As well as the map() change that I am 

Thirdly I had an off-hand hash comment about making the hashing algorithm 
fail gracefully if the hashing function was not working well.  Well I did a 
lot of looking at Perl's hashing algorithm in hv.c and hv.h, and I am not 
sure it is feasible.  That is, enough of the API is exposed in the HE and 
HEK structs that there would be a huge overhead in having a bucket really 
populated by a linked list.  Oh, you could do it.  For instance if 
(he)->hent_hek is NULL then follow (he)->hent_next to a node in a balanced 
binary tree.  But it would be a lot of overhead, and I for one don't feel 
comfortable suggesting a change like that.  (Does everyone consistently uses 
the convenience macros?)

BTW something random I noticed.  Wouldn't the hash value be better in HE 
than HEK?  Too late to change it now, but since compilers like to allocate 
things in powers of 2 that should save a couple of pointers per hash 


PS The patch:

--- pp_ctl.c.bak        Tue Mar 21 00:42:26 2000
+++ pp_ctl.c    Tue Apr 25 04:03:36 2000
@@ -736,6 +736,8 @@
        if (diff > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
            shift = diff - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
            count = (SP - PL_stack_base) - PL_markstack_ptr[-1] + 2;
+           if (shift < count)
+               shift = count; /* Avoid shifting too often */

            src = SP;

Get Your Private, Free E-mail from MSN Hotmail at

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About