Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Perl TK performance issue

by perltux (Monk)
on Dec 05, 2012 at 07:17 UTC ( [id://1007221]=perlquestion: print w/replies, xml ) Need Help??

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!

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 some_perl.pl
    nytprofhtml --open
Re: Perl TK performance issue
by perltux (Monk) 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?

      plain listbox/combobox?

      FWIW, it takes about 2 seconds for the sub to run for me, plus a few more (I guesstimate 4) for Tk to actually draw it

      OTOH, wxPerl pops up an equal amount of widgets in 1 sec, and it takes 1 sec to destroy them all

      Both take up about the same amount of RAM

      Its fairly similar to Tk (snippet of code generated by wxglade)

      $self->{label_A} = Wx::StaticText->new($self, -1, "A", wxDefaultPositi +on, wxDefaultSize, ); $self->{bank1_sizer2_combo1} = Wx::ComboBox->new($self, -1, "", wxDefa +ultPosition, wxDefaultSize, [], wxCB_DROPDOWN); $self->{bank1_sizer2_combo2} = Wx::ComboBox->new($self, -1, "", wxDefa +ultPosition, wxDefaultSize, [], wxCB_DROPDOWN); $self->{bank1_sizer2_slider} = Wx::Slider->new($self, -1, 0, 0, 10, wx +DefaultPosition, wxDefaultSize, wxSL_VERTICAL|wxSL_AUTOTICKS|wxSL_LAB +ELS|wxSL_TOP); $self->{bank2_sizer2_combo1} = Wx::ComboBox->new($self, -1, "", wxDefa +ultPosition, wxDefaultSize, [], wxCB_DROPDOWN); $self->{bank2_sizer2_combo2} = Wx::ComboBox->new($self, -1, "", wxDefa +ultPosition, wxDefaultSize, [], wxCB_DROPDOWN); $self->{bank2_sizer2_slider} = Wx::Slider->new($self, -1, 0, 0, 10, wx +DefaultPosition, wxDefaultSize, wxSL_VERTICAL|wxSL_AUTOTICKS|wxSL_LAB +ELS|wxSL_TOP); $self->{bank3__ck_sizer2_a} = Wx::CheckBox->new($self, -1, "", wxDefau +ltPosition, wxDefaultSize, ); $self->{bank1_sizer2_combo1}->SetMinSize(Wx::Size->new(30, 21)); $self->{bank1_sizer2_combo1}->SetSelection(-1); $self->{grid_sizer_1} = Wx::GridSizer->new(49, 3, 0, 0); $self->{bank1_sizer2} = Wx::BoxSizer->new(wxHORIZONTAL); $self->{bank2_sizer2} = Wx::BoxSizer->new(wxHORIZONTAL); $self->{bank3__ck_sizer2} = Wx::BoxSizer->new(wxHORIZONTAL); $self->{grid_sizer_1}->Add($self->{bank1_sizer2}, 1, wxEXPAND, 0); $self->{grid_sizer_1}->Add($self->{bank2_sizer2}, 1, wxEXPAND, 0);

      Distribution is easy with http://www.citrusperl.com//http://www.cavapackager.com/ for many platforms

      There is even my wxWidgets / wxPerl / wxGlade tutorial

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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1007221]
Approved by bitingduck
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-24 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found