in reply to Re^5: Run Perl 5 in the Browser! (JIT Compilation)
in thread Run Perl 5 in the Browser!
Is WASM JIT-optimized?
I'm not an expert, but WebAssembly really is meant for running stuff much faster than JavaScript. Copy-and-pasting some quotes from https://webassembly.org/ and https://en.wikipedia.org/wiki/WebAssembly (see also https://developer.mozilla.org/en-US/docs/WebAssembly):
WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.
It is meant to enable executing code nearly as fast as running native machine code.
The Wasm stack machine is designed to be encoded in a size- and load-time-efficient binary format. WebAssembly aims to execute at native speed by taking advantage of common hardware capabilities available on a wide range of platforms.
And from https://bellard.org/jslinux/ (the original author of QEMU):
... I converted the JSLinux asm.js code to C and converted it back to Javascript with emscripten ! With a careful tuning, the new version is now faster than the hand-coded asm.js version.
Here are some more virtual machines in the browser (although I'm not sure if they're WebAssembly, I just think it's cool*): https://copy.sh/v86/
I haven't tested yet whether the 2-3x slowdown I measured compared to native code might be due to the debug assertions that I currently still have enabled.
Don't you think that for little UI callbacks handling some AJAX compiling the whole Perl core to 4 MB WASM is kind of overkill?
It sure is! But it's Perl! :-D
Seriously though, I think the overhead of loading WebPerl is fine for my use case: a single-page, long-running application that does a lot of data exchange with the server. Writing all the data-handling code in JavaScript was getting tiresome, something that Perl can really help with.
If a web application consists of a lot of single pages, loading WebPerl into each of them is probably not going to be particularly performant.
(* Update: In fact, I figured that if I can't get perl compiled with Emscripten, in the worst case I can boot a VM in the browser, run a perl in there, and communicate with that, and yes I'm aware of how insane that is ;-D )
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: Run Perl 5 in the Browser!
by LanX (Saint) on Aug 22, 2018 at 22:01 UTC | |
by haukex (Archbishop) on Aug 22, 2018 at 22:08 UTC | |
by LanX (Saint) on Aug 22, 2018 at 22:23 UTC |