Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
perlcc
or Reducing the startup cost of perl programs.
In the beginning…
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/9512/msg00900.html
(What’s a modem?)
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/9512/msg00904.html
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/9601/msg00124.html
Perl run states
• BEGIN
• Code is always executed as soon as it’s seen.
• UNITCHECK
• Code is run (LIFO) just after each fi...
B.pm
• Compiler backend.
• Allows a Perl program to delve into its own innards
• Used by B::C to generate state informatio...
O.pm
• Interface to the compiler
• perl -MO=WHATEVA program.pl
• puts program into -c mode
• creates a CHECK block which r...
B::C
• Reduces your compile time to near zero by freezing
state at end of CHECK block
• perl -MO=-qq,C,-O3,-omyprog.c mypr...
File handle gotchas
• opening file handles during compile and expecting
them to functon at run time
• BEGIN { open($fh, ‘<‘...
What B::C is not
Doesn’t speed up your
program.
(mostly)
Can’t statically compile in XS
(mostly)
Can’t live independent of
libperl
(mostly)
What B::C can do
Speeds page hit of
traditional CGI apps.
( No running process when idle )
Shrink your program memory
size.
• Package removal during C code generation
• COW strings stored as C strings
• duplicates...
Reducing your Moose
startup time
(Eventually)
https://code.google.com/p/perl-compiler/issues/detail?id=350
#damnitstevan
B::C Time Line
• 1995 - Announcement
• 1996 - Compiler development started (B, O, B::C)
• 1998 - a8581515f - Integrated in...
Today
• cPanel initiated effort to get B::C working.
• cPanel Perl code can compile and run against 5.14.4
• perlcc script...
In the Past
$> cpanm B::C
#Installs perlcc into your perl bin directory
$> perl -MO=-qq,C,-O3,-fno-fold,-ot/C-COMPILED/
CO...
Example
$> cpanm B::C
$> perlcc -o foo foo.pl
$> ./foo
Hello World!
Tomorrow
• B::C Working on latest perl
• Compiled perl modules to .so files
• Byte Loader?
• B::CC
More information?
• irc.perl.org #compiler
• Issues: https://code.google.com/p/perl-compiler/issues/list
• Contribute: htt...
perlcc made easy or, how to make a CGI Moose app
Upcoming SlideShare
Loading in …5
×

perlcc made easy or, how to make a CGI Moose app

1,528 views

Published on

Based on recent work on the B::C module, it's now possible to build a working binary which can do away with the majority of startup expense a typical perl program would have.

In this talk, I'll explain:
- What the perlcc compiler does and doesn't do.
- How to setup the perl compiler.
- How to pre-compile a perl script into a binary for faster execution.
- Discuss the common mistakes one makes when building a perl binary and how to work around them.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

perlcc made easy or, how to make a CGI Moose app

  1. 1. perlcc or Reducing the startup cost of perl programs.
  2. 2. In the beginning… http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/9512/msg00900.html
  3. 3. (What’s a modem?) http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/9512/msg00904.html
  4. 4. http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/9601/msg00124.html
  5. 5. Perl run states • BEGIN • Code is always executed as soon as it’s seen. • UNITCHECK • Code is run (LIFO) just after each file is compiled • CHECK • Code is run LIFO after ALL compilation • B::C hooks here to do it’s magic • INIT • Runs FIFO at beginning of run time • Does NOT run if module is loaded at runtime. • END • Run LIFO after exit() http://perldoc.perl.org/perlmod.html
  6. 6. B.pm • Compiler backend. • Allows a Perl program to delve into its own innards • Used by B::C to generate state information at the end of the CHECK block
  7. 7. O.pm • Interface to the compiler • perl -MO=WHATEVA program.pl • puts program into -c mode • creates a CHECK block which runs B::WHATEVA::compile with some info from the compile process.
  8. 8. B::C • Reduces your compile time to near zero by freezing state at end of CHECK block • perl -MO=-qq,C,-O3,-omyprog.c myprog.pl • captures perl running state and writes out myprog.c • compiled binary will start at INIT state
  9. 9. File handle gotchas • opening file handles during compile and expecting them to functon at run time • BEGIN { open($fh, ‘<‘, ‘/var/log/foo’) or die } • sub later { while(<$fh>) {…} } • This also goes for things like numeric handles to external libaries ( i.e. openssl handles (IO::Socket::SSL) • https://rt.cpan.org/Public/Bug/Display.html?id=95452
  10. 10. What B::C is not
  11. 11. Doesn’t speed up your program. (mostly)
  12. 12. Can’t statically compile in XS (mostly)
  13. 13. Can’t live independent of libperl (mostly)
  14. 14. What B::C can do
  15. 15. Speeds page hit of traditional CGI apps. ( No running process when idle )
  16. 16. Shrink your program memory size. • Package removal during C code generation • COW strings stored as C strings • duplicates consolidated to 1 string. • Strings, Arrays, Hashes optimized to perfect size.
  17. 17. Reducing your Moose startup time (Eventually) https://code.google.com/p/perl-compiler/issues/detail?id=350 #damnitstevan
  18. 18. B::C Time Line • 1995 - Announcement • 1996 - Compiler development started (B, O, B::C) • 1998 - a8581515f - Integrated into core (5.005) • November 2003 - Perl 5.6.2 • December 2007 - Removed in 5.10.0 • June 2014 - Mostly Stable - 5.14.4
  19. 19. Today • cPanel initiated effort to get B::C working. • cPanel Perl code can compile and run against 5.14.4 • perlcc script does all the magic now • perlcc -e ‘print “Hello worldn”’; ./a.out • perlcc -o foo foo.pl • Optimizations (-O1/-O2/-O3)
  20. 20. In the Past $> cpanm B::C #Installs perlcc into your perl bin directory $> perl -MO=-qq,C,-O3,-fno-fold,-ot/C-COMPILED/ CORE—io--print.c t/C-COMPILED/CORE—io—print.t $> perl script/cc_harness -q t/CORE-CPANEL/io/CORE —io—print.c -o t/CORE-CPANEL/io/CORE—io—print.bin $> ./t/CORE-CPANEL/io/CORE—io—print.bin
  21. 21. Example $> cpanm B::C $> perlcc -o foo foo.pl $> ./foo Hello World!
  22. 22. Tomorrow • B::C Working on latest perl • Compiled perl modules to .so files • Byte Loader? • B::CC
  23. 23. More information? • irc.perl.org #compiler • Issues: https://code.google.com/p/perl-compiler/issues/list • Contribute: https://github.com/rurban/perl-compiler • master (unstable) • release (most recently released to CPAN) • CPAN: https://metacpan.org/pod/B::C • Me: Todd Rinaldo <toddr@cpan.org>

×