{"id":23,"date":"2026-11-21T12:08:00","date_gmt":"2026-11-21T12:08:00","guid":{"rendered":"https:\/\/php127.hazyhaar.fr\/blog\/?p=23"},"modified":"2026-11-22T04:03:18","modified_gmt":"2026-11-22T04:03:18","slug":"en-09-speed","status":"publish","type":"post","link":"https:\/\/php127.hazyhaar.fr\/blog\/en-09-speed\/","title":{"rendered":"The speed of php127"},"content":{"rendered":"<table>\n<thead>\n<tr>\n<th>Donn\u00e9e \/ Data<\/th>\n<th>Valeur \/ Value<\/th>\n<th>Date<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>mesure.revision<\/td>\n<td>e0a4a88<\/td>\n<td>2026-11-20<\/td>\n<\/tr>\n<tr>\n<td>vide.php127<\/td>\n<td>765 \/ 141<\/td>\n<td>2026-11-20<\/td>\n<\/tr>\n<tr>\n<td>add.php127<\/td>\n<td>1232 \/ 265<\/td>\n<td>2026-11-20<\/td>\n<\/tr>\n<tr>\n<td>appel.php127<\/td>\n<td>3485 \/ 787<\/td>\n<td>2026-11-20<\/td>\n<\/tr>\n<tr>\n<td>lecture.php127<\/td>\n<td>1541 \/ 390<\/td>\n<td>2026-11-20<\/td>\n<\/tr>\n<tr>\n<td>concat.php127<\/td>\n<td>3618 \/ 999<\/td>\n<td>2026-11-20<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This article describes the slowness observed in php127&#039;s historical measurements, their method and the fixes that followed. The data block at the top summarises the micro-benchmarks; the blog&#039;s source record links other figures to their files. The diagnostic of 2026-11-20 (<code>diagnostic-boucle.out.md<\/code>) covers e0a4a88, and the performance report of the same day (<code>constat-pratiques-performance.md<\/code>) is distinguished from later records.<\/p>\n<h2>Why count instructions rather than seconds<\/h2>\n<p>The measuring machine was loaded: its load ranged from 34 to 43 on 30 cores. Under these conditions, the same binary gave between 1.36 and 1.64 s for 50 million iterations of the same loop. Such a spread does not allow a decision between two versions that differ by 20%.<\/p>\n<p>The measure retained is therefore that of the processor counters, through <code>perf stat<\/code>: the number of machine instructions and cycles per loop iteration, on a performance core pinned with <code>taskset<\/code>, over 50 million iterations, with the cost of the empty script subtracted. Instruction counts are reproducible to the unit, and cycles vary by about 3%. The <code>compter.sh<\/code> script in the diagnostic&#039;s working folder does this calculation.<\/p>\n<h2>The measurements<\/h2>\n<p>Five micro-benchmarks were measured, each in a loop: the empty loop, an addition <code>$s+=$i<\/code>, a function call <code>f($i)<\/code>, an array read <code>$x=$a[$i&amp;7]<\/code> and a concatenation <code>&#039;x&#039;.$i<\/code>. The reference is PHP 8.3.6 started without a configuration file.<\/p>\n<p>The result, in instructions per iteration: 765 for the empty loop under php127 against 30 under PHP, a factor of 25; 1232 against 75 for the addition, factor 16; 3485 against 163 for the call, factor 21; 1541 against 123 for the read, factor 12.5; 3618 against 559 for the concatenation, factor 6.5. Cycles follow the same order of magnitude, with factors from 8 to 25.<\/p>\n<h2>Where the time goes<\/h2>\n<p>The diagnostic establishes one central point. php127 executes 4.5 to 5.4 instructions per cycle and mispredicts almost no branches. It does not wait for memory: <strong>it executes too many instructions per PHP operation<\/strong>. The Go language is not at fault as such. A toy interpreter written in Go, with the same instruction format, goes down to 197 instructions per empty loop iteration in stack form, and to 35 in register form with fused instructions.<\/p>\n<p>The measured causes are the following:<\/p>\n<ul>\n<li><strong>the preamble of each instruction<\/strong>. On e0a4a88, the virtual machine looked up a map, checked memory and copied the instruction. This preamble accounted for 47% of the empty loop profile. The 47 cycles per dispatch against 6 for the toy describe the total dispatch cost, not the preamble alone;<\/li>\n<li><strong>the call machinery<\/strong>. Preparing, passing arguments, calling and returning costs 44% of the call profile. Frames and call descriptions are copied by value, twice each;<\/li>\n<li><strong>the arena<\/strong>. Every access to an arena value decodes a full header and checks its bounds; <code>ArrayGet<\/code> accounts for 36% of the array read profile;<\/li>\n<li><strong>concatenation<\/strong>, which makes one Go allocation per operation, takes a lock on every access to the memory zone and copies the bytes three times.<\/li>\n<\/ul>\n<h2>What was fixed on trial<\/h2>\n<p>The diagnostic tried local fixes, numbered e1 to e6, on a trial tree on which the test suites concerned passed. Taken together, they bring the empty loop from 765 down to 480 instructions, the addition from 1232 to 774, the call from 3485 to 2773, the read from 1541 to 1086 and the concatenation from 3618 to 2727. The gap with PHP 8.3.6 then remains between a factor of 5 and a factor of 18.<\/p>\n<p>These figures apply to the trial tree built on e0a4a88, not to reference revision 5b31e86. The local fixes were later integrated as 89b0f27 (<code>j7\/c7_perf_locales.rendu.txt<\/code>); integration does not turn trial-tree measurements into measurements of 5b31e86.<\/p>\n<h2>After the diagnostic<\/h2>\n<p>The diagnostic proposed three structural steps. Their status must be distinguished from its historical estimates:<\/p>\n<ul>\n<li>the hot-loop restructuring, called S1, was integrated as 265dc17 according to the record of 2026-11-20 at 23:40; the change from about 100 to about 20 instructions was a diagnostic estimate, not a measurement of reference 5b31e86;<\/li>\n<li>translate the intermediate code at load time into register-based code with fused instructions. On the toy interpreter, this change takes the empty loop from 197 to 35 instructions;<\/li>\n<li>replace the byte arena with typed Go tables, which affects the memory limit and the cycle collector. It costs more than the other two, and it will be decided after measuring the first two.<\/li>\n<\/ul>\n<p>None of these gains is acquired until it has been measured on the head.<\/p>\n<h2>What this means in practice<\/h2>\n<p>The initial report of 2026-11-20 gave 149 s for <code>Routing<\/code>, 116 s for <code>Yaml<\/code> and 58 s for Twig. Evening records (<code>c7_perf_biblio.out.md<\/code>, <code>c7_perf_locales.out.md<\/code>) give about 10 to 13 s for <code>Routing<\/code> without establishing an identical protocol. The log for the node integrated as 5b31e86 later gives 23.178 s under php127 against 680 ms under PHP 8.3.6 (<code>j9\/c9_commande_ecarts_3.reprise.out.md.err<\/code>). These dated observations do not form a constant-protocol series.<\/p>\n<p>These measurements do not establish traffic capacity. On this site, the blog is served behind an nginx page cache, while the shop is served without a page cache. This choice does not establish a load limit from the cited micro-benchmarks and suites alone.<\/p>\n<p class=\"php127-traduction\"><a rel=\"alternate\" hreflang=\"fr\" href=\"https:\/\/php127.hazyhaar.fr\/blog\/fr-09-la-vitesse\/\">Lire en fran\u00e7ais<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Donn\u00e9e \/ Data Valeur \/ Value Date mesure.revision e0a4a88 2026-11-20 vide.php127 765 \/ 141 2026-11-20 add.php127 1232 \/ 265 2026-11-20 appel.php127 3485 \/ 787 2026-11-20 lecture.php127 1541 \/ 390 2026-11-20 concat.php127 3618 \/ 999 2026-11-20 This article describes the slowness observed in php127&#039;s historical measurements, their method and the fixes that followed. The data block [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-en"],"_links":{"self":[{"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":2,"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/php127.hazyhaar.fr\/blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}