DEV Community

Cover image for Creating a High Performing PHP alternative backend on GraalVM. Part 1 : Introduction
David Maye
David Maye

Posted on Edited on

Creating a High Performing PHP alternative backend on GraalVM. Part 1 : Introduction

The idea is mentioned in the title: create a new backed for the PHP language. The name of the backend? HPP (High-Performing PHP) running on the GraalVM. The project is available in a public Gitlab repository.

There is previous work done on this matter by Andrin Bertschi that seems to show that PHP on GraalVM could improve it's performance to up to 859%. Even though I start from "scratch" using the Simple Language example from Oracle, I will still be heavily inspired by Adrin project. The objective is to have a stable alternative that can be switched simply on user decision.

It's going to be somehow hard to do because GraalVM allows you to create a programming language using the Java Language and the Truffle Framework, and I know neither of those, nor on Programming Language Design and it's components (Parser, Lexer, memory management, etc.) The only average proefficiency I have is in PHP and some quick intense experience with other programming language (C, D, JS) aquired either on curiousity or due to my main activity (Web Dev).

So this series is more of resume on lessons learned during my 1 hour coding session.

Work done today

Renaming SL to HPP

The only thing I did today was rename every namespaces and class, method and properties names. This also included a big directory renaming. I couldn't do it all due to time constraint (1 hour coding session) so maybe I will keep working tomorrow. Althout it was very fun to work on Java. I remember that Java was one of the programming language I always wanted to program on, so I'm delighted to work on it as a tool for my main Programminga Language of interest: PHP.

Concepts learned today

The pom.xml file

This project uses maven (a.k.a mvn). It is project manager/project builder for the Java language owned by apache. And every pom.xml file is a description of the work to be done by the project: it contains about the name of the project, group name (author group name), the artefact ID and the modules.

In the project, there are 4 directories: language, launcher, standalone, tck. Each of the directories are referenced in the pom.xml file as a module of the project. And inside each modules leaves another pom.xml file that describes the module.

It's similar to a composer.json project: contains info on the project, and each packages/bundles of the project contains it's own composer.json file. In this case I have to work on 4 modules in a single project, which is a very interesting approach I'm not used to.

Bytecode is generated under target directory of each module

While renaming folders, I observed that there was some target directory in each modules that mimicked the src directory and contained some bytecodes. That was due to the fact that a previously compiled the project using mvn package command. I read about bytecode languages (compiled and then interpreted), but I never seen one in action. That's was cool

Namespace seems tied to the project directory structure

It is interesting that namespace naming must match the directory. In the case of PHP the namespace is conditioned by the composer file. I can have a directory in src/Project and define the project as available under Seigisoft\SeigiCms\FrameworkBundle. An example is available here: https://gitlab.com/seigisoft/seigicms/seigicms-framework-bundle.

module-info.java as a Dependency class

So that's interesteing. There is a class that acts as a dependency manager called module-info.java. Seems like while pom.xml is more focused on project building aspect, this file declares the dependencies that will be used by the classes under that directory. I have to admit that I start to like Java: this move seems overkill and weird, but at the same time it doesn't bother me too much.
It seems like it is responsible of the classes that will be injected (using the require <package> statement), the classes that will be publicly exported for other modules to use (using the export <package> statement) and the interfacing aspect of the language (using provides <provider> with`). Very interesting.

Top comments (0)