Hacker News new | ask | show | jobs
by continuations 2086 days ago
PHP is implemented in C, right?

What makes a PHP version implemented in a JVM 9x faster than PHP implemented in C?

6 comments

The JVM version implements a JIT compiler; the C version implements an interpreter. So it's the same thing that makes PyPy faster than CPython, Java 1.3 faster than 1.2 and the first release of Chrome's V8 faster than earlier JavaScript implementations.

PHP 8 also introduces a JIT compiler, which is presumably less mature but more complete: https://wiki.php.net/rfc/jit

also, the implementation we're talking about is not a complete implementation of the PHP language.

It's easy being faster when you're doing less.

The JVMs are amazingly fast.

A majority of the dynamic compilation research goes into JVMs. (The remainder being apportioned mostly to the javascript vms and the clr, with mike pall waving his luajit hat in the distance.)

An overwhelming majority of GC research also goes into JVMs, thanks to Jikes RVM.

Apart from the interpreter part, the GraalVM project also has a focus on creating native images, basically compiling directly to the assembly of the architecture. That's what the native results are from.

Ever seen a java Spring project start in 0.015s, or a java rest service living in 16-32mb of ram? With graal these things are now possible.

They are using CPU intensive synthetic benchmarks to compare tight loops, fannkuch-redux, spectral-norm, and similar done in PHP code and aren't directly implemented in C.

The kind of things they are benchmarking aren't what people typically use PHP for.

The JVM compiles the PHP code to highly optimised machine code at runtime. The C implementation doesn't compile to machine code at all (or I think they only just started doing it and it's very limited.)
Mostly because PHP is implemented very poorly. Its used to be really slow (its a little bit better now with newer versions) and it always amazed me, because of its basically a thin wrapper on C.

I guess PHPs core types are very inefficient and the team behind PHP lacks time to really do a rewrite. A prime example is the PHP "array". Its not a list, its not an array, but more of a weird object thing. PHP is full of these weird things that are probably hard to optimize (in the PHP runtime)

I'll point out that in the latest Techempower Benchmarks[1] PHP makes up 20% of the fastest 25 frameworks. It also makes two appearances before the first Java framework.

PHP might not be suited to every application, but it's certainly not slow.

[1] https://www.techempower.com/benchmarks/

Thats a total BS claim. I took a quick look at the top 25, and the ones that made the list (top 25) that are PHP based are:

- 11: php-ngx-pgsql

- 12: workerman-pgsql

- 22: workerman

- 23: php-ngx-mysql

- 25: Swoole

Here you see a trend, workerman and swoole are BOTH nodejs clones, they have a event loop and are non-blocking. This means you CANNOT use 95% of core PHP because its blocking by nature. These are all a non-starter for 99.9% of PHP based apps. Also swoole is a PHP C-extension, not a "installable" framework like say Symfony is, taht said these are NOT frameworks at all, not sure why they are on the list?

Heres the REAL rankings of the PHP frameworks that are used in the wild:

- 299: codeigniter

- 323: fatfree

- 369: cakephp

- 370: symfony

- 377: laravel

PHP occupies the lower bottom of the ranking, and will probably always be there becuase og how PHP is built. The core model of execution is always going to be slower than a "running" program. This is evident with the nodejs clones.

I have to point out that what you say applies only on the "Fortunes" benchmark. On the others benchmarks, Java always comes before PHP. I'll also add that most people don't use the top performing frameworks (most people use Laravel and Symfony for PHP, which are near the bottom), but that applies to everything here.

[edit]: clarification

Huh? Nearly every PHP job is Laravel or Symfony nowadays, at least in Europe.
I wasn't clear, sorry. What I meant to say is that most people use Laravel and Symfony, which are nowhere near the top performing PHP frameworks on the benchmark.