PHP Speed Tooling

PHP Speed Tooling

Partial function application, tokens and Flow.

Interactive version — https://slide.darkwood.com/slides/php-speed-tooling

Mathieu Ledru

November 27, 2026

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

17 slides
  1. Darkwood · PHP 8.6 · Flow PHP Speed Tooling Partial

    Function Application, Tokens and Flow How much tooling can PHP provide before another abstraction earns its place? PHP 8.6 experiment · Darkwood @matyo91
  2. Slide 2 · 1/1 · représentation statique The rule Need

    argument binding? → PFA Need lightweight source structure? → PHP tokens → foreach Need actual orchestration?→ consider Flow Need to iterate local files? Use the PHP primitive first. 01 | rule Version interactive : https://slide.darkwood.com/slides/php-speed-tooling @matyo91
  3. Experiment 1 · closure tax fn ($value) => transform($value, $configuration)

    ↓ transform(?, $configuration) PHP 8.6 Partial Function Application The extra closure existed only to bind one argument. 02 | pfa @matyo91
  4. FCC vs PFA FIRST-CL ASS CALL ABLE fn ($ctx) =>

    $step->apply($ctx) $step->apply(...) PARTIAL FUNCTION APPLICATION fn ($v) => applyBudget($v, $budget) applyBudget(?, $budget) PFA starts where FCC stops: some arguments are already known. 03 | fcc-pfa @matyo91
  5. ? vs ... foo(?, $config) exact placeholder required in the

    resulting Closure foo('value', ...) remaining list stays open optionals keep their defaults Bound arguments are evaluated when the partial is created. 04 | placeholders @matyo91
  6. Slide 6 · 1/2 · représentation statique PFA goes straight

    into Flow Flow changed: 0 lines $flow = new Flow( static fn (BenchmarkState $state): BenchmarkState => loadPassages($state, $corpus), ); ↓ $flow = new Flow(loadPassages(?, $corpus)); $flow ->fn(applyBudgetToState(?, 12)) ->fn(collect(?, $box)); 05 | flow Version interactive : https://slide.darkwood.com/slides/php-speed-tooling @matyo91
  7. Slide 6 · 2/2 · représentation statique PFA goes straight

    into Flow Flow changed: 0 lines PFA already produces the Closure Flow expects. 05 | flow Version interactive : https://slide.darkwood.com/slides/php-speed-tooling @matyo91
  8. Pipe ≠ Partial Application PFA |> Flow bind arguments thread

    a value execute jobs $input |> removeNoise(...) |> normalizeWhitespace(...) |> applyBudget(?, 14); They are complementary, not competing syntax. 06 | pipe @matyo91
  9. First conclusion We almost added nothing. No partial() No curry

    API No pipe emulation No PHP 8.6 requirement for Flow PHP already solved the syntax problem. 07 | nothing @matyo91
  10. PHP Speed Tooling What if the same rule applies to

    tools written about PHP? Need a parser stack? ↓ Maybe just tokens Choose the cheapest representation that still contains the information you need. 08 | tooling @matyo91
  11. Our tool · tools/pfa-opportunities PHP files ↓ PhpToken::tokenize() ↓ ignore

    whitespace / comments ↓ find simple arrow functions ↓ PFA / FCC / ignore No php-parser 09 | scanner ~540 lines report only @matyo91
  12. Conservative by design ACCEPTED fn ($x) => foo($x, $bound) →

    foo(?, $bound) fn ($x) => $step->apply($x) → $step->apply(...) REJECTED fn ($p) => $p->toArray() fn ($x) => foo(bar($x), $c) fn ($x) => complicated($x) && other($x) False negatives are acceptable. False refactoring advice is not. 10 | conservative @matyo91
  13. What did it find? Zero is a result. 144 498,107

    51,663 PHP files bytes significant tokens 0 3 0 PFA candidates FCC candidates Flow src The selected production code did not contain obvious PFA migration sites. 11 | findings @matyo91
  14. Tokens are enough… until they aren’t TOKENS ARE ENOUGH FOR

    simple syntactic shapes arrow functions argument positions method call patterns AST / SEMANTICS MAY BE NEEDED FOR scope types name resolution reliable automated rewriting Speed Tooling means avoiding unnecessary machinery — not refusing necessary machinery. 12 | limits @matyo91
  15. Should the scanner use Flow? PL AIN PHP foreach ($files

    as $file) { scanFile($file, $config); } FLOW $scan = scanFile(?, $config); $flow = new Flow($scan); $flow(new Ip($file)); $flow->await(); Plain ~79.5 ms Flow ~120.2 ms Peak ~6 MiB both foreach wins here. Flow added orchestration without an orchestration problem. 13 | foreach @matyo91
  16. When Flow earns its place PHP PRIMITIVES argument binding callables

    pipeline syntax tokenization simple iteration FLOW multiple IPs driver-controlled execution error jobs events IP strategies await() Flow becomes useful when execution itself becomes the problem. 14 | boundary @matyo91
  17. PHP primitive first. PFA instead of an adapter abstraction. PhpToken

    instead of a parser stack. foreach instead of an orchestration engine. Add Flow when execution becomes orchestration. @matyo91

More Decks by Mathieu Ledru

Other Decks in Programming