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

I have a Perl application that reads in data from spreadsheets and also creates a GUI interface (using Perl/Tk). This has to be started a number of times during the day and I need to decrease the time it takes before the user gains access to the application. Is there a way I can process all the reading and GUI building and then save the application at this point? The user could then initiate the application from this point each time the application has to be started. If not what other techniques are available to speed up the process (I have seen the Saving Data Structures section of the Programming Perl reference manual which seem to offer possibility about reading ion the data from the spreadsheets).
  • Comment on getting a Perl application to start as quick as possible

Replies are listed 'Best First'.
Re: getting a Perl application to start as quick as possible
by sgifford (Prior) on Jan 06, 2005 at 19:27 UTC

    The first thing you should do when trying to speed something up is profile it (with something like Devel::DProf) to see what's taking it so long. If it's loading all the modules, something like pperl or a Perl compiler will help. If it's loading the data, maybe a different data structure would help.

    In general, getting your users to minimize your app instead of exiting it should help no matter what's causing the slowness.

Re: getting a Perl application to start as quick as possible
by zentara (Cardinal) on Jan 06, 2005 at 19:41 UTC
    It might sound obvious, but how about starting the app, then withdrawing the mainwindow to an icon? From the end users point of view, he clicks the icon, and the program comes up immediately. The only drawback is it uses some cpu while it sits there, but you could probably work out a scheme to put some "sleep" into it. Maybe let it sleep while it's iconified, and have it fully awake when it's deiconified?

    You probably need to intercept the window manager's close command..

    #prevents mw from closing and iconifies instead $mw->protocol('WM_DELETE_WINDOW' => sub { $mw->iconify });

    For sleep, maybe something like this

    tksleep($mw, 100); sub tksleep { # Like sleep, but actually allows the display to be # updated, and takes milliseconds instead of seconds. my $mw = shift; my $ms = shift; my $flag = 0; $mw->after($ms, sub { $flag++ }); $mw->waitVariable(\$flag); }

    I'm not really a human, but I play one on earth. flash japh
Re: getting a Perl application to start as quick as possible
by borisz (Canon) on Jan 06, 2005 at 19:22 UTC
    Try to use pperl instead of perl.
    Boris
Re: getting a Perl application to start as quick as possible
by biosysadmin (Deacon) on Jan 07, 2005 at 00:39 UTC
    You could try storing the data read from spreadsheets using Storable:
    use Storable; my %spreadsheet_data; if ( -f $storage_file_name ) { %spreadsheet_data = %{ retrieve( $storage_file_name ) }; } else { # read in all of your data into %spreadsheet_data store \%spreadsheet_data, $storage_file_name; }
    Deriving what the $storage_file_name should be would be better left to someone who knows Windows better than I.

    Cheers. :)

Re: getting a Perl application to start as quick as possible
by Courage (Parson) on Jan 06, 2005 at 20:36 UTC
    1. probably this will not be liked by others, but it appears that http://search.cpan.org/~vkon/Tcl-Tk/ have faster startup time and smaller memory footprint than perl/Tk
    2. when some other (small) Tcl/tk application will be started, startup time of previous item will be a bit better yet
    3. call update several times from different points of starting, this probably visually be faster.

    Best regards,
    Courage, the Cowardly Dog

Re: getting a Perl application to start as quick as possible
by Anonymous Monk on Jan 06, 2005 at 22:14 UTC
    Can you just make your application a daemon (windows service) and have it "interact with the desktop" by creating GUI's ? This would probably require ActiveState tools or you would have to compile a .exe file that invoked the Perl application in order to get the "interact with the desktop" rights and such. Meanwhile, I really think you might be able to profile the code, look over your design, and make it lighter weight without going to those extremes. I have Perl/Tk apps that start up pretty quickly, but they are also rather small so maybe that's not fair.
Re: getting a Perl application to start as quick as possible
by holli (Abbot) on Jan 06, 2005 at 19:24 UTC
    autoloading could also help.