Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Trading compile time for faster runtime?

by LanX (Saint)
on Apr 20, 2022 at 14:16 UTC ( [id://11143130]=note: print w/replies, xml ) Need Help??


in reply to Trading compile time for faster runtime?

You should be more specific which kind of optimization at compile time you are missing, I doubt there is much potential left.

Perl has dynamic typing which means higher performance is only possible by JIT-ing once the types are (statistically) known (i.e."code paths" are recorded at run-time)

The other way is explicit typing of variables by the author, allowing to optimize crucial sub-routines at compile time.

JS (JIT) resp Typescript (Typing) can do both now.

But as I said, please show us a way to improve ahead of time compilation of vanilla Perl without types.

edit

Furthermore I'm not sure if Perl can even write such optimized machine code without being bundled with a C-compiler.

Theoretically once could use typed variables to create Inline::C blocks. But I'm ignorant about other possibilities here...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re: Trading compile time for faster runtime?

Replies are listed 'Best First'.
Re^2: Trading compile time for faster runtime?
by melez (Sexton) on Apr 20, 2022 at 17:22 UTC

    I'm not talking about compiling perl into machine code. I'm talking about spotting some common patterns and replacing them with optimized versions that do the same thing. Still with perl OPs.

    Perl already does this. Subroutines with empty prototype and constant return value are inlined (not actually called on the runtime). If statements that have constant false condition will not be included in the internal compiled structure at all. Currently existing optimizations are pretty straightforward, I think mostly constant folding, to avoid long startup time of a program. What I mean is to have more of those with less focus on fast compile time, as an executable flag for easy on/off. Yes, potential gains may not be worth it or there might be some technical reasons why this isn't viable.

      could you show an example, please?

      perl -MO=Concise FILE will show you the OP tree.

      NB: the tree doesn't mean the order of execution, you have to read the line numbers.

      C:\>perl.exe -MO=Concise -e"map {$_++} 1..3" d <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 7 <|> mapwhile(other->8)[t5] vK ->d 6 <@> mapstart K ->7 3 <0> pushmark s ->4 - <1> null lK/1 ->4 - <1> null lK/1 ->7 c <@> leave lKP ->7 8 <0> enter l ->9 9 <;> nextstate(main 2 -e:1) v:{ ->a b <1> postinc[t2] sK/1 ->c - <1> ex-rv2sv sKRM/1 ->b a <#> gvsv[*_] s ->b 5 <1> rv2av lKPM/1 ->6 4 <$> const[AV ] s ->5 -e syntax OK

      more options in B::Concise

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Can't, as I said - I have close to zero experience with XS. My question was hypothetical, but others have pointed out that it was attempted already, both in the core as well as on CPAN.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-23 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found