
Improving Performance of PHP for Arm64 and Impact on Amazon EC2 M6g Instances - zdw
https://idk.dev/improving-performance-of-php-for-arm64-and-impact-on-amazon-ec2-m6g-instances/
======
tambourine_man
With Apple and Amazon pushing ARM this hard, we should see some amazing chips
in the next 5-10 years.

I haven't been this exited about hardware in a long time. Maybe it's because
of my Raspberry Pis, but I'm childishly giggly.

~~~
ed25519FUUU
I'm also not sure why I'm excited about ARM64 hardware as well. At least it's
partly because in the imbedded world ARM operating systems are prevalent.

Also, it's clear Intel rested on their laurels and resisted real innovation
for a _long time_. Now with heavy hitters entering the field (Apple, Amazon,
etc), hopefully we see some real innovation in this silicon space.

What I'd like to see is SoCs with accelerated AI chips, similar to what's in
the recent iPhones. If that type of hardware becomes widely available on the
macs we almost all of us in SV develop on, then the libraries will follow.

~~~
UhDev
Almost all develop on? lol!

~~~
hu3
Some people live in bubbles within bubbles.

Fortunately, we have data to confirm our suspicions:
[https://insights.stackoverflow.com/survey/2020#technology-
de...](https://insights.stackoverflow.com/survey/2020#technology-developers-
primary-operating-systems)

~~~
bloopernova

        Windows   45.8%
        MacOS     27.5%
        Linux     26.6%
        BSD       0.1%
    

Huh, I didn't expect the split to that even. That's pretty gratifying, in my
opinion. That's far, far closer to 33% per major platform than I thought
possible. (all possible apologies to the BSD demons out there, we love y'all
and I wish it were more like 25% per major platform, all 4 of them)

------
ksec
There are lots of work happening on Ruby as well. Example [1]. It seems
everyone is hiding their geeky excited inner child and having fun working on
it.

I am starting to wonder if Apple timed this all along or did the two ARM
announcement all within 6 months happens to be coincidence.

[1] [https://bugs.ruby-lang.org/issues/17021](https://bugs.ruby-
lang.org/issues/17021)

------
hanikesn
The correct url is: [https://aws.amazon.com/blogs/compute/improving-
performance-o...](https://aws.amazon.com/blogs/compute/improving-performance-
of-php-for-arm64-and-impact-on-amazon-ec2-m6g-instances/)

------
rob-olmos
(In case this isn't changed to the official AWS blog link)

"There are two other patches that impact the performance of the WordPress-
NGINX benchmark, and both have been applied to master and PHP-7.4 branch:"

A patch to disable the use of huge pages in memory allocator fixed a 10%
performance regression: [https://github.com/php/php-
src/commit/928c42211f737640e4dc3c...](https://github.com/php/php-
src/commit/928c42211f737640e4dc3c9702ba833c3059bddf)

The patch to enable the Zend Optimizer on ARM64 accounts for about 5% of
better performance on M6g instances [https://github.com/php/php-
src/commit/4d7df449d0ab389b01b45f...](https://github.com/php/php-
src/commit/4d7df449d0ab389b01b45fa1bb9bf2b4a8755545)

------
tiffanyh
> "The JIT is currently developed on x86 and is based on Lua’s JIT. As Lua’s
> JIT supports ARM64, ..."

I'm confused when they say it's based on LuaJIT? Do they mean PHP is being
transcoded to Lua and run by LuaJIT.

Or do they mean that PHP-JIT is based on "DynASM" \- which is a subproject of
LuaJIT?

[http://luajit.org/dynasm.html](http://luajit.org/dynasm.html)

~~~
tyingq
Yes, they are using DynASM. [https://github.com/php/php-
src/blob/master/ext/opcache/jit/R...](https://github.com/php/php-
src/blob/master/ext/opcache/jit/README.md)

------
sroussey
They have their work cut out for them if they want to support PHP 8 on ARM
since that version will come with a JIT.

~~~
timthorn
The article includes benchmarks of PHP8 beta on AArch64.

Quoting: "PHP-8 plans to feature a new JIT compiler that optimizes the PHP
byte-code in the Opcache. The JIT is currently developed on x86 and is based
on Lua’s JIT. As Lua’s JIT supports ARM64, we work with PHP developers to
enable and to tune the Opcache JIT in PHP-8 to get the best performance on AWS
Graviton processors."

~~~
sroussey
That’s awesome. I haven’t kept up... last I saw they were rolling their own.
LuaJIT is great.

~~~
aseipp
They absolutely are rolling their own JIT (doing otherwise would reduce its
value substantially or simply be infeasible.) The sentence above is just badly
written in the original article. The PHP 8 JIT uses the "DynASM" library to
help generate code in memory — which was originally developed for use in
LuaJIT 1. (LuaJIT 2 does not use DynASM for its own runtime code generation,
but it does use DynASM instead as a sort of "super" macro assembler when you
compile it, making it easier to write its optimized, per-architecture
interpreter.)

But "just" putting encoded instructions in a memory buffer is the easy part of
it all, and that's all DynASM does. You still need thousands of lines of code
backing it up to actually generate the right instructions, and implement
appropriate optimizations.

------
bluedino
Are there similar articles out there for other languages like Python or Node?

~~~
ma2rten
I'm assuming node already is fast on ARM since it uses the same javascript
engine as a major mobile web browser.

~~~
floatboth
And CPython is already slow on everything. :D

But PyPy has an arm64 JIT since last year:
[https://morepypy.blogspot.com/2019/07/pypy-jit-for-
aarch64.h...](https://morepypy.blogspot.com/2019/07/pypy-jit-for-aarch64.html)

------
ramshanker
Now we have following companies agressively pushing ARM64 optimization.

1\. Amazon

2\. Apple

3\. ?? Add your here. :)

~~~
rvz
In the next 15 years, we'll say the same thing with RISC-V.

~~~
ac29
Has there been much traction in building RISC-V application processors?
Something like a RISC-V Raspberry Pi style SBC would be interesting to see,
but the only thing like that I am aware of was enormously expensive (the
HiFive Unleashed @ $999). I think the semi-open, high-volume, competitive ARM
SoC market is going to make it very hard for RISC-V to find a niche in higher
performing devices.

~~~
homarp
how about [https://www.seeedstudio.com/Sipeed-Maix-
Cube-p-4553.html](https://www.seeedstudio.com/Sipeed-Maix-Cube-p-4553.html) ?

RISC-V Dual-Core 64-bit, with FPU and some 'machine learning' accelerator

or cheaper [https://www.seeedstudio.com/Sipeed-Longan-Nano-RISC-V-
GD32VF...](https://www.seeedstudio.com/Sipeed-Longan-Nano-RISC-V-
GD32VF103CBT6-Development-Board-p-4205.html)

~~~
ac29
Those are both microcontroller-class RISC-V processors (of which there are
many), not something capable of running Linux.

~~~
homarp
I get your point.

You still can get linux on the K210 [https://www.cnx-
software.com/2020/02/17/how-to-build-run-lin...](https://www.cnx-
software.com/2020/02/17/how-to-build-run-linux-on-kendryte-k210-risc-v-nommu-
processor/)

and it seems it's mainlined now:
[https://www.phoronix.com/scan.php?page=news_item&px=RISC-
V-C...](https://www.phoronix.com/scan.php?page=news_item&px=RISC-V-Changes-
Linux-5.8)

------
Thaxll
Any benchmarks with x86 proc? Nice to see ARM being supported more and more
but what are the performance vs Intel / AMD CPUs?

~~~
why_only_15
> With the software changes in PHP-7.4 and PHP-8, WordPress can serve up to
> 17% more pages per second on M6g.4xl vs. M5.4xl [M5.4xl is AWS's default x86
> processor]. Combined with the 20% lower cost of M6g instances, running
> PHP-7.4 and WordPress provides up to 34% better price/performance on M6g
> instances vs. M5 instances.

------
rafaelturk
Thanks to Amazon and Apple CPUs are Sexy again.

