Performance: let debug mode serve fresh woven classes from OPcache (debug hot request 13 ms vs 5.5 ms in production)

Abierto
#814 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
28/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
php

Línea de trabajo

Start by reading follow-up issue #745, the freshness work tracked in #815, and the transformation performance test named in the acceptance criteria. Compare the three proposed loading approaches, focusing on XDebug breakpoint mapping and magic constants before proposing a design. Done means an approved approach preserves woven output, cache maps, and magic constants; avoids woven-file reads and recompilation on hot debug requests; and still re-weaves changed sources.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Enhancement Performance To Be Discussed

Implementation note: start in plan mode. XDebug breakpoint mapping and magic constants need an approved design before any code is written.

Measured with goaop/shop-demo (PHP 8.5.12, framework b755e57). Follow-up of #745, which made fresh untransformed files opcache-cached in debug mode and deliberately kept woven files on the filter.

Problem

In debug mode every woven class is loaded through php://filter/read=go.source.transforming.loader/resource=<original>. OPcache never caches a filtered include, so on every request each woven class:

  • is checked for freshness (filemtime, filesize, isFreshSince());
  • has its cached copy read with file_get_contents();
  • is compiled from scratch.

Measurement (hot request, OPcache warm, 94 woven classes)

debug => true debug => false
request time 13.0 ms 5.5 ms
filemtime / filesize calls 323 / 239 0 / 0
file_get_contents calls 94 0
profiled share of class loading + cache metadata 20 % 6 %

(323 filemtime includes ~84 redundant re-stats of tracked resources, tracked in #815.)

Why the filter is used today

Debug mode serves woven code through the filter so that PHP reports the original path for the included file. XDebug breakpoints set in the original source then hit, and __FILE__/__DIR__ of the woven body point at the original file (#679).

Options to evaluate in the plan

  1. Opt-in flag (e.g. a Features:: bit or a debug sub-option): include fresh woven files by their cache path, like production. Breakpoints then have to be set in the cache files, or mapped by the IDE (path mappings), and magic constants are already rewritten by MagicConstantTransformer.
  2. Automatic: use the cache path when no step debugger is active (xdebug_info('mode') without debug, or extension_loaded('xdebug') === false), and the filter otherwise. This keeps the freshness checks either way.
  3. Keep the filter but make it cheaper (no file_get_contents() of a separate file, e.g. by reading the cached content through the stream directly). The compile cost remains.

Acceptance

  • Woven output, cache maps and magic constants identical with and without the new path.
  • With the new path, a hot debug request does no file_get_contents() for woven classes and no compilation (OPcache hits), measured with the shop demo or the fixture project.
  • A changed source is still re-woven on the next debug request.
  • composer test, composer analyze; composer test:performance:transformation unchanged.

Estimate

Up to −7 ms per debug request on this app (proportional to the number of woven classes loaded). High: debugger integration semantics, design decision, cross-platform paths.


Generated by Claude Code

Lenguaje dominante
PHP
Estrellas
1.7k
Forks
166
Merge medio
23 h 58 min
PR fusionados (30 d)
40

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de goaop/framework

Todos los issues de goaop/framework

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.