WordPress / WordPress/wordpress-playground

Measure the performance of PHP.wasm

Open
#205 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

[Type] Performance
Dominant language
JavaScript
Stars
2k
Forks
462
Avg merge
18h 44m
Merged PRs (30d)
33

Description

Description

Let's find what's the baseline performance of the WASM build of PHP (and WordPress) compared to the system-native one.

First step: Identify prior art on benchmarking WordPress and PHP performance, then run it with PHP.wasm and WordPress Playground and compare to native PHP and regular WordPress.

Some quick thoughts that will likely be completely rewritten:

  • Setup a few archetypical sites (a store, a blog, a content site with a lot of data)
  • Test time to HTTP response with a single client
  • Stress test with many clients
  • Define and use "typical HTTP caching" settings, stress test with those in place
  • (future) Test time to first paint
  • (future) Test web vitals

To get any feel on this at all, I wrote a simple script that measures how many json_encode("Hello World") it can do in 5 seconds and these are the results:

With php test.php:

Serialized 'Hello World' to JSON 63862450 times in 5 seconds.

With PHP=8.1 npx @php-wasm/cli test.php:

Serialized 'Hello World' to JSON 30654414 times in 5 seconds.

With the interactive code block

Serialized 'Hello World' to JSON 27264540 times in 5 seconds.

In this oversimplified test, WebAssembly PHP is two times slower than the native build. That's not bad for a build that wasn't tweaked for performance at all yet. Still, it's not measuring a real-world use-case. I'd like to get more realistic numbers and also find ways to optimize that build. I suspect using a JS runtime is dragging – perhaps WASI + native WASM runtime would help.

<?php

$start_time = microtime(true); // Get the start time

$count = 0; // Set the initial count to 0

while (microtime(true) - $start_time < 5) { // Run the loop for 5 seconds
    json_encode("Hello World"); // Serialize "Hello World" to JSON
    $count++; // Increment the count
}

echo "Serialized 'Hello World' to JSON $count times in 5 seconds.";

cc @adamsilverstein @ThierryA @dmsnell @jsnajdr

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the documented test.php microbenchmark and the existing PHP.wasm CLI invocation, then research prior art for benchmarking PHP and WordPress. Define representative WordPress sites and comparable native and WebAssembly runs; done means documented performance results for the proposed scenarios and any evidence about optimization opportunities.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php, wasm, wordpress
Domain
backend, performance, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.