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

Dear Monks

I am interested to see if I could speedup the initialization of my perl program, by compiling it.

However all the attempts result in an error.
Here is my test program
#!/usr/bin/perl -l use strict; use warnings; use DateTime ; print "hello" ;
I tried to compile it like
$> perlcc -o out t20.pl /usr/bin/perlcc: t20.pl did not compile, which can't happen:Starting c +ompile Walking tree DateTime::Locale::Base saved (it is in DateTime::Locale::root's @ISA) DateTime::TimeZone saved (it is in DateTime::TimeZone::UTC's @ISA) DateTime::TimeZone::OffsetOnly saved (it is in DateTime::TimeZone::Fl +oating's @ISA) DateTime saved (it is in DateTime::Infinite's @ISA) Prescan Saving methods Can't locate object method "IVX" via package "B::NV" at /usr/lib/perl +5/5.8.8/i586-linux-thread-multi/B/C.pm line 650. CHECK failed--call queue aborted.
and
$> perl -MO=CC,-ot20.c t20.pl Can't locate object method "_save_common_middle" via package "B::FAKEO +P" at /usr/lib/perl5/5.8.8/i586-linux-thread-multi/B/C.pm line 389. CHECK failed--call queue aborted.

Any suggestion how to fix the problems with the B package ?

Thanks a lot
LuCa

Update: I have to add that perlcc compiles only when I ommit 'use DateTime'
Update2: Thnx for the suggestions, I'll try mod_perl and PAR!

Replies are listed 'Best First'.
Re: Error when compiling perl-script to executable
by citromatik (Curate) on Jul 06, 2007 at 11:11 UTC

    If you want to make your script executable try PAR::Packer (the Perl Archive Toolkit)

    #!/usr/bin/perl use strict; use warnings; print "Hello World\n" ;

    Compile it with the "pp" utility:

    % pp -o hello hello.pl

    That creates "hello" that can be run directly:

    % ./hello Hello World

    This tool is very effective in packaging stand-alone applications written in perl (packs all the modules, etc...), but I don't know at what extend the performance of the resulting executable is increased

    Hope this helps

    citromatik

      but I don't know at what extend the performance of the resulting executable is increased

      It isn't, performance is decreased. The way that PAR works is by creating an executable that contains all of the files that will be necessary to run the script embedded in itself. At runtime, each of those files will be extracted into a temporary directory (I think they are extracted as needed, rather than all at once at the beginning, but I'm not sure). The overhead of extracting the files is going to add a bit of extra time to the running of the script, though I don't think it's enough to worry about if PAR solves other problems for you.


      We're not surrounded, we're in a target-rich environment!
        PAR does do caching. So your startup penalty is for the first run only. HOWEVER, it does NOT "compile" any code... so PAR will run the same scripts at the same speed as before.
Re: Error when compiling perl-script to executable
by fenLisesi (Priest) on Jul 06, 2007 at 10:57 UTC
    perlcc docs have this:
    The code generated in this way is not guaranteed to work. The whole codegen suite (perlcc included) should be considered very experimental. Use for production purposes is strongly discouraged.
    If it is a web application that you are trying to speed up, you may try mod_perl. You may also be interested in FastCGI and SpeedyCGI.

    Cheers.

Re: Error when compiling perl-script to executable
by bart (Canon) on Jul 06, 2007 at 10:58 UTC
    perlcc was a failed experiment that has been abandoned a long time ago (10 years or so). I don't think anybody here will fix it for you.

    Can anybody explain to me why it still in core?

      I guess that if you are one of the rare few for whom perlcc works, you prefer that perlcc remains in the Perl distribution. Phrased a bit more provocative, the Backward Compatibility Polic(e|y) of Perl prevents that removal.

        From the changelog:
        __________________________________________________________________ [ 28790] By: rgs on 2006/09/06 14:04:33 Log: Remove perlcc and the byteloader Branch: perl

        Dave.