Leveraging 70% of the web: a PHP backend for PureScript

News:

The initial benchmark gave 1m30s. After dozens of compiler optimizations, the tests are now successful after a run of ~1.7s. That is a great step forward.

The benchmarks I’ve seen often (online) show Node (V8) to be 2 to 5 times faster than PHP 8, for this kind of task. Our benchmark seems to reflect that reality fairly accurately. The compiler has therefore likely reached its peak performance area.

In our context, the x3 difference (only x2 compared to purerl) is not a problem:

  • We’re targeting a segment of the web that, while certainly the majority, is also focused on factors other than pure performance (presence, visibility, lower costs, etc.). For advanced projects (e.g. containerized stack, full DevOps control…), JS will often remain a better compiler backend (or even: Go, Erlang…).
  • In the vast majority of cases, the main bottleneck remains I/O. As a result, the difference in performance isn’t even noticeable.

Support for Aff has also been added, backed by the Revolt event loop and PHP 8.1+ Fibers. The behavior of the event loop in the compiled PHP code perfectly mirrors its Node.js counterpart: asynchronous operations are handled transparently without blocking the OS thread, and the main process will automatically wait for all pending Aff tasks to complete before exiting.

In parallel, the project structure has been fully reorganized to align with the standard conventions of other alternate backends (like purerl, purescm, or purescript-go). We now have:

  • A dedicated FFI ecosystem based on standard forks (prelude here, effect here, aff here, etc.).
  • A standalone compiler repository.
  • A ready-to-use starter template to easily bootstrap new projects.

And of course, the README has been updated to make onboarding easy for any developer who wants to compile their PureScript project into PHP.

So… The compiler itself is now at a very advanced stage in terms of features and performance. My next immediate priorities are to clean up and refactor the codebase to make it truly maintainable, and then move on to the next phase: improving the DX (e.g. npm install) and building a real-world POC to battle-test the implementation.

I’ll keep you posted!

1 Like