/trufflephp

An efficient PHP implementation built on GraalVM

Primary LanguageJavaApache License 2.0Apache-2.0

Build Status codebeat badge CodeFactor Codacy Badge

A PHP implementation built on GraalVM

Graalphp is an experimental just-in-time (JIT) compiler and runtime for PHP 7.4+ hosted on GraalVM.

Abstract

PHP is a popular, weakly typed, general purpose programming language. Originally designed for building dynamic web pages, the language has since gained wide adoption in server-side web development. In this work, we describe the design and implementation of graalphp, an experimental compiler and runtime for PHP hosted on Truffle and GraalVM. GraalVM is a virtual machine that supports execution of multiple languages, which are implemented as Abstract Syntax Tree (AST) interpreters based on Truffle. GraalVM uses Graal as its JIT compiler to compile frequently executed code fragments to machine code. We implement a subset of the PHP language to run synthetic benchmarks by The Computer Language Benchmarks Game. We compare peak performance of our implementation against PHP 7 as well as alternative implementations such as HHVM, JPHP and an early alpha version of PHP 8. Experimental results indicate that our runtime reaches competitive results with performance gains of up to 859% compared to PHP 7. These preliminary results suggest that a Truffle-hosted PHP implementation might be significantly faster than existing language implementations.

design

This project was launched as an undergraduate thesis at ETHZ.

Build and Run

For a container image with development and benchmark dependencies see ./docker/.

# Build Dependencies: Linux environment, maven, ant, GraalVM
# download GraalVM from https://github.com/graalvm/graalvm-ce-builds/releases
$ export JAVA_HOME=/path/to/graalvm
$ mvn package
$ ./graalphp <php-file.php>
# build native image:
$ export JAVA_HOME=/path/to/graalvm
$ $JAVA_HOME/bin/gu install native-image
$ export GRAALPHP_BUILD_NATIVE="true"
$ mvn package

Feature Set

High Level Overview of implemented features, current runtime code base. ca. 4000 LOC. Implemented features are chosen to support execution of the Computer Language Benchmark Game. https://github.com/abertschi/graalphp/tree/master/benchmarks/evaluation

Non exhaustive list of features:

  • Datatypes: int, float, boolean, arrays (sequences) of these types
  • Unconditionally defined functions
  • Variables in function scope, global scope
  • Binary, unary, operations
  • while, do while, for, if

More Resources