http://www.perlmonks.org?node_id=1007221

perltux has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm trying to build a relatively complex window with a grid of 50x17 widgets. It works fine but it takes about 6 seconds to open up on my AMD Phenom II x4 2.6GHz running Linux (this is a child window spawned by the main program window when the user presses a button).
I do realise Perl TK is an interpreted language and that therefore performance is often lower than if it was written in C or C++, but I would much appreciate it if you could have a look at the code and tell me if there is any way to optimise it so to speed up the creation of this window.

Here is the code:

sub KitEditWin { $rywin=$mw->Toplevel; $rywin->geometry("930x600"); $rywin->title('RM50 Rhythm Kit Editor'); my $ryw=$rywin->Scrolled('Frame', -scrollbars=>'e' )->pack(-side=>'top', -anchor=>'n', -fill=>'both', -expand=>1); $ryw->Label( -text=>'Bank' )->grid(-row=>0, -column=>1); $ryw->Label( -text=>'Voice 1' )->grid(-row=>0, -column=>2); $ryw->Label( -text=>'Attenuation')->grid(-row=>0, -column=>3); $ryw->Label( -text=>'Bank' )->grid(-row=>0, -column=>5); $ryw->Label( -text=>'Voice 2' )->grid(-row=>0, -column=>6); $ryw->Label( -text=>'Attenuation')->grid(-row=>0, -column=>7); $ryw->Label( -text=>'Mod' )->grid(-row=>0, -column=>9); $ryw->Label( -text=>'Bal' )->grid(-row=>0, -column=>10); $ryw->Label( -text=>'Flt' )->grid(-row=>0, -column=>11); $ryw->Label( -text=>'Pan' )->grid(-row=>0, -column=>12); $ryw->Label( -text=>'Dcy' )->grid(-row=>0, -column=>13); $ryw->Label( -text=>'Vol' )->grid(-row=>0, -column=>14); $ryw->Label( -text=>'P.b' )->grid(-row=>0, -column=>15); $ryw->Label( -text=>'Key' )->grid(-row=>0, -column=>16); for (my $a=1; $a<=49; $a++) { my $end; if ($a<=24) { $end=1; } else { $end=0; } for (my $v=0; $v<=$end; $v++) { my $aa=$a; my $vv=$v; # bank selection $ry_bank_sel[$a][$v]=$ryw->BrowseEntry(%BEntry_defaults, -variable => \$ry_bank[$a][$v], -choices => \@banks_array, -font => 'Sans 9', -width => 6, -listheight => 10, -browsecmd => sub{ RefreshVceList($aa, $vv);} )->grid(-row=>$a, -column=>1+($v*4), -padx=>4); $ry_bank_sel[$a][$v]->Subwidget("choices")->configure(%cho +ices_defaults); $ry_bank_sel[$a][$v]->Subwidget("arrow")->configure(%arrow +_defaults); # voice selection $ry_voice_sel[$a][$v]=$ryw->BrowseEntry(%BEntry_defaults, -variable => \$ry_voice[$a][$v], -choices => $voiceshash{$ry_bank[$a][$v]}, -font => 'Sans 9', -width => 12, -listheight => 10 )->grid(-row=>$a, -column=>2+($v*4), -padx=>4); $ry_voice_sel[$a][$v]->Subwidget("choices")->configure(%ch +oices_defaults); $ry_voice_sel[$a][$v]->Subwidget("arrow")->configure(%arro +w_defaults); # Attenuation $ryw->Scale(%Scale_defaults, -variable => \$ry_att[$a][$v], -to => 15, -from => 0, -tickinterval => 3, -length => 100, -command => sub{ } )->grid(-row=>$a, -column=>3+($v*4), -padx=>4); $ryw->Label(%Scale_label_defaults, -textvariable => \$ry_att[$a][$v], -width=>2 )->grid(-row=>$a, -column=>4+($v*4), -padx=>4); } # Modulation $ryw->Checkbutton( -variable => \$ry_mod[$a] )->grid(-row=>$a, -column=>9); # Balance $ryw->Checkbutton( -variable => \$ry_bal[$a] )->grid(-row=>$a, -column=>10); # Filter $ryw->Checkbutton( -variable => \$ry_flt[$a] )->grid(-row=>$a, -column=>11); # Pan $ryw->Checkbutton( -variable => \$ry_pan[$a] )->grid(-row=>$a, -column=>12); # Decay $ryw->Checkbutton( -variable => \$ry_dcy[$a] )->grid(-row=>$a, -column=>13); # Volume $ryw->Checkbutton( -variable => \$ry_vol[$a] )->grid(-row=>$a, -column=>14); # Pitch bend $ryw->Checkbutton( -variable => \$ry_pbd[$a] )->grid(-row=>$a, -column=>15); # Key off $ryw->Checkbutton( -variable => \$ry_kyo[$a] )->grid(-row=>$a, -column=>16); } }


Just to give you an idea this is how the window looks like:
http://www.linuxtech.net/files/rm_manager_ryed.png

Thanks a lot in advance for any suggestions!