Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^6: Run Perl 5 in the Browser!

by chromatic (Archbishop)
on Aug 22, 2018 at 23:16 UTC ( #1220884=note: print w/replies, xml ) Need Help??

in reply to Re^5: Run Perl 5 in the Browser! (JIT Compilation)
in thread Run Perl 5 in the Browser!

Actually I'm wondering why this is not generally used for JITing Perl.

Three semi-informed guesses:

  • Perl's internal data structures (SVs and casting between similarly shaped structs) don't make JITting easy.
  • Perl's internal implementation (opcodes being a big mass of macros calling functions calling macros) doesn't make JITting easy.
  • Code paths and function bodies are too long to JIT well.

These can all be solved, but it would surprise me if they were solved easily.

Replies are listed 'Best First'.
Re^7: Run Perl 5 in the Browser!
by ikegami (Pope) on Aug 23, 2018 at 01:45 UTC

    I think the fundamental problem is that Perl has too many hooks (operation overloading, constant overloading, variable type overloading, custom opcodes, etc) that prevent optimizations without changing the language. We can't even guarantee that 2 returns a number (e.g. when using use bigint;), so we're stuck with fat opcodes that must be able to accept any kind of value.

      Yeah, given that observing a variable at the Perl level could cause SV upgrades within an opcode, maybe it's better to say the challenges are:

      • Polymorphic data structures at the C level; with
      • SV upgrades in opcodes; leading to
      • Large opcode function sizes

      We're not talking about JITting a five line Smalltalk method that's monomorphic across 80% of calls here. It would surprise me if the average opcode didn't expand to a size larger—and quite a few basic blocks more‐than LLVM wants to try to JIT.

        Nah, implicit type conversions is something JIT compilers can handle.

      JIT is about optimizing the main cases and observing the edge cases.

      You don't need guarantees because you just fall back to the generic solution if the input variables become unusual.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        It's the checking that makes it slow right now, so I'm not sure how what you said helps.

Re^7: Run Perl 5 in the Browser!
by LanX (Cardinal) on Aug 23, 2018 at 00:37 UTC
    I'm not a JIT expert, but if one of the strategies is to reduce a dynamic type to a static one, one could use Inline::C to generate a static version of a functions body.

    I also remember Steffen Müller giving a talk demonstrating some Perl JIT.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2020-10-22 01:39 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (225 votes). Check out past polls.