3

Is there a way to save a compiled version of my perl scripts?

Or a way to do a JavaScript style compile where you just remove comments, whitespace, etc?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
700 Software
  • 85,281
  • 83
  • 234
  • 341
  • 3
    No, but if you tell us what you're doing (and why you think it matters) we may be able to offer some useful advice. – Michael Carman Oct 11 '10 at 13:19
  • 1
    Is this really the best way to optimize your code? Did you profile it first? Probably possible, but I don't think it's common practice. IMHO it seems like a waste of time and something of a last resort. – Øyvind Skaar Oct 11 '10 at 13:21
  • 4
    Sorry, minifying does not reduce start-up time in a significant way. There's a reason why the minifyer mentioned below is in the `Acme` namespace. – daxim Oct 11 '10 at 13:47
  • Some of the scripts are >300 KB and they do not change often and even then I only hope to save a third of a second each time it runs :) – 700 Software Oct 11 '10 at 14:15
  • 1
    If you profile your code I'm sure you can save a lot more.. did you check out Devel::NYTProf? – Øyvind Skaar Oct 11 '10 at 14:37
  • 2
    @daxim: Wait, do you mean all those gizmos from Acme that Will E. Coyote recommended me don't do anything useful? – ninjalj Oct 11 '10 at 18:01

6 Answers6

6

You're trying to optimize in the wrong place. If you are running scripts in a web/cgi environment, there is no need to take a compile hit every time the script is executed. The scripts should be running persistently, which you can do with Apache mod/perl, FastCGI, or a number of newer technologies and frameworks such as Plack and Catalyst. If you are more specific about your needs, you will discover that there are a number of options available to you.

Ether
  • 53,118
  • 13
  • 86
  • 159
  • Catalyst isn't itself a means of running webapps persistently, though it basically requires itself to be run in some persistent way. Plack is also not a means of running webapps persistently, it it just a way of connecting webapps running whatever plack-enabled framework with whatever plack-enabled web app serving technology (including plain old non-persistent CGI). There are native servers for Plack which let you run your app persistently, though. – MkV Nov 23 '10 at 02:20
2

Do you realize that Javascript is minified to save bandwidth, not startup time or runtime? And that the practice of minifying Javascript started in the times of dialup connections?

Sure, there was a time where interpreted programs were often minified like that, but back then typical CPUs were Z80s and 8086's running at 4-8 MHz, and using loads of cycles to execute a single instruction. To show: my Athlon XP-M 2400 is ~10,000 times faster than my 8MHz 8086 for CPU-bound programs.

ninjalj
  • 42,493
  • 9
  • 106
  • 148
  • We didn't have JavaScript back when we had dialup connections. We had static pages made with mud tablets and sticks. JavaScript showed up with the invention of the printing press. Shesh. – the Tin Man Nov 23 '10 at 23:55
2

Try the perl compiler, to C B::C or to B::Bytecode (similar to python pyc).

http://search.cpan.org/dist/B-C/perlcompile.pod

szabgab
  • 6,202
  • 11
  • 50
  • 64
rurban
  • 4,025
  • 24
  • 27
1

You could use PPI to strip out comments and POD.

Alan Haggai Alavi
  • 72,802
  • 19
  • 102
  • 127
1

Perl::Squish is the "minifier" you're looking for. Caveat: It's not going to help you at all. You're trying to optimize on the wrong end.

tsee
  • 5,034
  • 1
  • 19
  • 27
-2

If you're doing this for fun you might want to check out parrot vm

If not.. see my comment ;)

Øyvind Skaar
  • 2,278
  • 15
  • 15