uniter / phpruntime

Runtime library for PHP environments
Other
14 stars 1 forks source link

What issues exist with using Webassembly type compilers to transfer PHP stdlib? #1

Open roundmidnight opened 6 years ago

roundmidnight commented 6 years ago

I saw your message about how you have a project to reimplement more of the PHP stdlib in javscript. I was curious to know if you had tried to use some of the existing compilers to do that - e.g. https://github.com/leaningtech/cheerp-meta/wiki - and what the issues/hurdles/problems are in practice.

asmblah commented 6 years ago

Hi @roundmidnight - can I assume you're talking about this discussion here: https://github.com/asmblah/uniter/issues/46 ?

I've considered using Emscripten here, but not experimented with it much other than some experiments with a JS build of the PCRE library for full support of the preg_* PHP functions - I hadn't heard of Cheerp before, thanks for the tip, it looks really interesting. I guess I would have no issue with pulling in certain standard PHP library functions written in C, providing their compiled version didn't add too much weight to the compiled JS bundle. I think we'll always want some standard library functions to be implemented in JS, but I can see how this could accelerate things if we could make it work.

Aside from the compiled size issue, I'd imagine another hurdle being the mapping of PHPCore's Value objects to and from the values that the C code would expect, but it would still be interesting to see what was feasible. Would you be interested in putting together a proof of concept of this?

Cheers!

roundmidnight commented 6 years ago

Hi, thanks for the reply. The "discussion" referenced was unite project note on github at https://github.com/asmblah/uniter -

_phpruntime is the extended "full" runtime library. After pulling in phpcore, it installs the remaining builtin classes and functions, such as arraymerge(...). Only a small subset of PHP's standard library has been implemented so far - please open a GitHub issue in the phpruntime repository if you would like to request something that is missing.

Thinking about the existing state of PHP, Javascript, Typescript, Web Assembly worlds and where they are going, I see the ability to convert big chunks of existing or new backend PHP library to javascript, asm.js, or Web Assembly could have broad utility. Node & Web Assembly both have a lot of momentum, and a lot of potentiial, starting from a small base.

Converting the standard library calls of PHP 7.X would be a key hurdle to running large chunks of existing PHP libraries. It's written in C. Some I'd try to figure out how much conversion could be done automatically, using tools like Cheerp, which leverages the large effort being put into creating Web Assembly as a new key target platform for C++, by way of LLVM.

I also noticed that a few years prior, the Facebook implementers of HipHop compiler for PHP, had implemented an LLVM backend for their parser and intermediate language. But they later dropped it from the code because their interest was in JIT compilation of PHP, and the LLVM optimizations weren't giving them any significant performance boost in that case for their virtual machine type framework. But they may still have their version of the stdlib organized in an interesting way to support current PHP.

asmblah commented 6 years ago

Ah I see - this sounds like something we should definitely look into. I know there isn't much (or anything, really) in the way of documentation in the various Uniter repositories, so do feel free to ask anything you need either here or in the Gitter room: https://gitter.im/asmblah/uniter

Thanks!