Hacker News new | ask | show | jobs
by sradman 2094 days ago
Truffle is an integration layer for interpreted languages in GraalVM. The canonical Truffle language included in the Graal distribution is GraalJS, a replacement for the now deprecated Nashorn JavaScript engine for the JVM. Similarly, TruffleRuby is an alternative to JRuby and GraalPython is an alternative to Jython. Neither of these Truffle implementations has gained traction and they will not until they fully implement the main frameworks for each ecosystem (Ruby on Rails and Django/NumPy respectively).

The same will hold true for a Truffle implementation of PHP. It will need to support the C interface components like PDO database drivers and the Laravel web framework.

The linked project was created as part of a graduate thesis and demonstrates the feasibility of GraalVM/Truffle as a performant polyglot platform. I'm not convinced that Ruby/Python/PHP integration with Java Bytecode is an important use case moving forward. It could have been when Rails/Django/Laravel were on top of the web framework game but the demand for this use case is diminishing.

3 comments

Efforts like this with GraalVM and the upcoming JIT in PHP 8 should lead to, I believe, that many of the existing C extensions of PHP to be converted to pure PHP implementations.

When you have a JIT based language you want as much to be executed in that language, jumping back and forth between PHP and C is a drawback from a JIT perspective.

However there exist many PHP C extensions that are just thin wrappers around large C libraries like cURL, it is not really feasible to implement that in pure PHP.

But with the introduction of a foreign function interface with PHP 7.4 that has made it possible to call C libraries with ease, as long the C library doesn't do too much macro magic, and to my understanding upcoming Java release ships with a much improved native bridge with better support for native types, these two thing could lead to, guessing here, that you only need to implement the bridge for each implementation but share the rest of the PHP wrapper code for that C library.

However the foreign function interface introduced in PHP 7.4 is signigfanctly slower that the old style C extension of Zend PHP, but to my understanding is that future evolution of the JIT could theoretically reduce that performance impact.

> When you have a JIT based language you want as much to be executed in that language, jumping back and forth between PHP and C is a drawback from a JIT perspective.

The Truffle solution to this is to run the C extension in the same JIT, so that's it's not a barrier to optimisation anymore.

> It will need to support the C interface components like PDO database drivers and the Laravel web framework.

Laravel does not have any C PHP modules in its codebase. While it makes use of drivers provided by them, it does not have any components that are written in C.

I read the original poster's post as Graalphp needs to support both PDO, the C extension, AND Laravel, specifically every language construct that Laravel uses.
Describing truffle implementations as alternatives to Java implementations is not quite correct. They are always alternatives for the reference implementations (CRuby, Cpython). They're also not really about integration with Java Bytecode

Also Truffle will let you run C extensions unlike regular jvm implementations due to the polyglot nature of Graal and Sulong