You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Hans de Groot <ha...@interspective.nl> on 2002/06/28 17:06:01 UTC
slow hashes with recursive loops?
Hi,
I made a function to sort a folder list (with childs/parents), I know it must be a silly method I use but it was the only one I could think of at the time.
The problem I now have is that is is very slow. I only have 128 folders but it takes like 5 secs to loop through this.
I have narrowed it down to the function below and I do not see the resaon why it would be sooooooooooooooo slow. specially if you considure I have many many hits on the database
and other silly this in the rest of the code. (It's for a website tool).
Then I remebered I read something about a bug or problem with embperl 2.x and hashes. I cannot find it anymore but I use embperl 1.3b5 on redhat 7.2 (but same on redhat 6.1)
Is there any work arround for this or something else I can do to speed things up? Right now I use $udat to store the tree list (ie I store the hashes in a string via join and every hit I split the string again into hashes.
It seems to me that this process shoudl take much longer jan just loop through that loop I made. But it's a hack and for now it works.
But people without cookies still get the slow version (Imagine 6 frames from which 3 use navigation is a 15 secs freeze.. )
Help
:-)
here my silly loop (note that the digit function does not take noticable time)
sub get_list()
{
my($tempparent)=shift;
my($step_size)=shift;
my($step_type)=shift;
my($subkey);
my($key);
$glob_lev++;
foreach $key (sort {$parentlist{$a} <=> $parentlist{$b}} keys %parentlist)
{
foreach $subkey (sort {$node{$a} <=> $node{$b}} keys %node)
{
if (($key eq $tempparent) && (exists $level{$tempparent,$subkey})) # deze node heeft child.
{
if ($glob_lev != $meet_lev)
{
$meet_lev=$glob_lev;
}
$count++;
$spacer="";
# Silly hash, 3 separate hashes for name, id, and level
$ruk=&digit($count,6);
$levelhash{$subkey}=$glob_lev;
$treehash{$ruk}=$spacer.$nodenaam{$subkey}; #Voor naam met indent
$parenthash{$ruk}=$key;
$key_hash{$ruk}=$subkey; # om de id terug te vinden
&get_list($subkey,$step_size,$step_type);
}
} # End for subkey
} #end for key
$glob_lev--;
}
Regards
Hans
------
Hans de Groot
Interspective Internet Services B.V.
Tel: +31 (0) 30 6001180
Fax +31 (0) 30 6044204
www: http://www.interspective.nl
email: hansg@interspective.nl
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: slow hashes with recursive loops?
Posted by Gerald Richter <ri...@ecos.de>.
Hi,
>
> I made a function to sort a folder list (with childs/parents), I know it
must be a silly method I use but it was the only one I could think of at the
time.
> The problem I now have is that is is very slow. I only have 128 folders
but it takes like 5 secs to loop through this.
>
> I have narrowed it down to the function below and I do not see the resaon
why it would be sooooooooooooooo slow.
Also I don't quite understand what you are doing here, it seems that you are
doing many many time the same sort, while the aruments to sort doesn't
change. At least I can't see in your code where you change %parentlist or
%node. So the first thing to do is to move these sort out of the loop and
perform them _before_ the loop, save the result in a array and use this as
argument to foreach. This should speed up your code many times (unless I
have overseen something). Maybe there are more constant operation that could
be moved out of the loop. Since I have to less knowlegde of your
datastructure, I can't say if there are more optimaziation possible.
> Then I remebered I read something about a bug or problem with embperl 2.x
and hashes. I cannot find it anymore but I use embperl 1.3b5 on redhat 7.2
(but same on redhat 6.1)
>
That has nothing to do with Perl hash. That was about some hashs that
Embperl 2 uses internaly and that only occurs if you have very huge
iteration of the same html code.
BTW. If you are using 1.3b5 I would recommend to update 1.3.4, but that's up
to you and has nothing to do with you problem.
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org