In the first part of the introductory article, we covered the origins of Peachpie. We mentioned the primary motivations behind the creation of a PHP compiler, which led to the development of Phalanger, the predecessor of Peachpie.The last post finished by pointing out the nuances and benefits of Microsoft’s Roslyn compiler, which paved the way for Peachpie. In Part II, we would like to explain in what ways Peachpie will outperform Phalanger and to what overall benefits we expect this to lead.
Improvements to Phalanger
Although Peachpie is still a work in progress, our past experience with the development and maintenance of Phalanger and analysis of the current status of PHP allow us to make several inferences about the value added of Peachpie.
From practical applications, we know for a fact that Phalanger left many areas with substantial room for improvement. Our users’ feedback and a continuous profiling of PHP applications allowed us to identify various bottlenecks that slowed Phalanger-compiled apps down by 10 and occasionally even up to 75%. Together with the benchmarks below, which were performed with Phalanger in March 2012, this yields multiple interesting results:
Source: Phalanger benchmarks
It is imperative to mention that this benchmarking study was conducted exactly four years ago, in 2012, and PHP has since improved drastically in terms of its performance. However, Peachpie will offer a multitude of architectural improvements and features, based on our experience with Phalanger.
The first roadblock that Peachpie effectively removes is the frequent garbage collection. Phalanger boxed all values by treating all types as Objects, which is a tremendous burden for garbage collection. Peachpie will include type analysis, which allows the developer to work with value types on a stack without the need to allocate them to a heap. Another enormous benefit of the type analysis itself is that it provides an increased security and resilience against runtime errors.
Additionally, the type analysis allows for a significantly better optimalization through both the compiler itself, as well as the JIT compiler in .NET. One of the most impressive benefits of Peachpie will then be an improved interoperability with C# projects, which will be able to use the compiled PHP code through a strongly typed interface, rather than generic objects.
Unlike Phalanger, Peachpie will prefer the option to execute code statically. This means that function calling and class instantiation will no longer be executed dynamically, and the resulting code will be more similar to that of static languages, such as C#. Not only will this enable a more precise type analysis, but it also paves the way for further optimizations conducted by the JIT compiler.
Last but not least, Peachpie will be an open platform that can easily be extended and enriched by new libraries.
The Benefits of Peachpie
The primary reasons why Peachpie makes sense through the benefits attached to it can be broken down into the following three categories:
- Increased performance of PHP apps: although we are not yet at a point where we can create benchmarking studies, we can build on the performance benefits generated by Phalanger (see benchmarking study above). Several factors combine in creating a significant increase in performance of PHP applications. Microsoft Roslyn allows for an approximately 100-times faster compile time compared to the Legacy .NET API. Additionally, the maintenance benefits associated with a reduction of garbage collection in Peachpie can already improve its runtime by around 20% compared to Phalanger. Finally, the static analysis allows us to eliminate a majority of the dynamicity, which can further double the speed of the program.
- Both-way .NET interoperability: as covered in Part I of this article, Peachpie-powered PHP applications will be interoperable with those written in a .NET language, and vice versa.
- Security: potential security shortcomings or lack of certificates in a PHP application can be eradicated by compiling the code into .NET and taking advantage of the security benefits of the Microsoft framework. Some of the value added of powering a PHP project with Peachpie are code obfuscation, distributing and deploying the PHP application without sources, signing compiled code with strong keys, and the fact that security restrictions are configured for the process in general.
The exact statistics and quantities by which PHP applications can be improved, for instance, will not be clear until the first benchmarking studies can be conducted for Peachpie. However, we have gathered immense amounts of experience and insights from developing the Phalanger compiler, which allows us to make relatively accurate predictions as to the functionality of Peachpie.
We are looking forward to presenting the outcomes of our first benchmarking studies in the weeks to come.