Skip to content

Commit 82d0647

Browse files
committed
Add native Rust extension write-up
The one native path actually shipped (PR #381/#423/#378). ~1.33x over optimized PHP under JIT (the original ~10x conflated lazy-AST + no-JIT). Code lives on those branches; documented here.
1 parent 4ad4c56 commit 82d0647

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

  • experiments/native-rust-extension
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Native Rust parser extension
2+
3+
**Origin:** the one native path actually built and shipped — PR #381 (the
4+
extension), follow-ups #384–#394, #423 (native-backed AST nodes), and #378 (which
5+
reworked the AST to materialize eagerly). The crate lives at
6+
`packages/php-ext-wp-mysql-parser/` on those branches; not copied here to keep this
7+
branch a clean diff against trunk.
8+
9+
**Idea:** skip the regex tricks; write the lexer and parser in Rust and ship them
10+
as an optional PHP extension for environments we control.
11+
12+
**Result (parser-only, AST materialized, this machine):**
13+
14+
| config | trunk PHP | optimized PHP | native |
15+
|-----------------------|-----------|---------------|--------------|
16+
| opcache + tracing JIT | ~28K QPS | ~57K | ~77K (~1.33×) |
17+
| no opcache / no JIT | ~12K QPS | ~34K | ~75K (~2.19×) |
18+
19+
The original "~10×" claim was too optimistic for two reasons, both confirmed:
20+
(1) the native pipeline loaded AST nodes LAZILY and the first benchmark never
21+
materialized them (materializing costs ~3.5×: ~265K → ~77K); (2) it compared
22+
native against pure PHP WITHOUT JIT. With JIT and materialization, native is only
23+
~1.33× over the optimized PHP parser.
24+
25+
**Verdict:** native is faster, but only ~1.3× over optimized PHP under production
26+
JIT — questionable whether the native build is worth maintaining. Notably, the
27+
optimized PHP parser run in validate-only mode (no node materialization, ~246K) is
28+
in the same league as the native lazy path, so the cheapest remaining win is
29+
PHP-side (skip materialization), not native.

0 commit comments

Comments
 (0)