Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Perl TK performance issue

by perltux (Scribe)
on Dec 05, 2012 at 07:17 UTC ( #1007221=perlquestion: print w/replies, xml ) Need Help??
perltux has asked for the wisdom of the Perl Monks concerning the following question:

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:

Thanks a lot in advance for any suggestions!

Replies are listed 'Best First'.
Re: Perl TK performance issue
by Anonymous Monk on Dec 05, 2012 at 09:51 UTC
    use Devel::NYTProf, try
    perl -d:NYTProf
    nytprofhtml --open
Re: Perl TK performance issue
by perltux (Scribe) on Dec 05, 2012 at 09:31 UTC
    Ok, just an update, I have narrowed down the performance issue to the BrowseEntry widgets, if I comment out the BrowseEntry widgets then the window shows up almost instantly.

    So it looks like BrowseEntry widgets (or at least the way I'm using them) are very cpu intensive.

    What could be functionally equivalent but more efficient substitute widgets for the BrowseEntry widget?
Re: Perl TK performance issue
by zentara (Archbishop) on Dec 05, 2012 at 10:59 UTC
    My only suggestion is to try another widget, like Tk::JComboBox. Also at the end of JComboBox's perldoc, is a list of alternative modules which can give the same functionality. I would look for the simplest and smallest module.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007221]
Approved by bitingduck
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2017-05-30 06:56 GMT
Find Nodes?
    Voting Booth?