Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Performance: unbounded parser-reflection AST cache during weaving (671 MB peak, −25% parse time when bounded)

Aperta
#749 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php

Direzione di ricerca

Start with src/Instrument/Transformer/WeavingTransformer.php and src/Instrument/Transformer/StreamMetaData.php, then trace how SourceTransformingLoader::ensureRegistered() and CacheWarmer initialize the transformation pipeline. Measure warmup with cache limits of 64, 256, and 1024, and run composer test:performance:transformation; done means woven output is unchanged and the chosen limit has before-and-after time and peak-memory measurements.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Enhancement Performance

Problem

ReflectionEngine::parseFile() (goaop/parser-reflection) keeps the AST of every parsed file in the static ReflectionEngine::$parsedFiles for the life of the process. The framework never calls ReflectionEngine::setMaximumCachedFiles().

Every woven file passes through it (src/Instrument/Transformer/StreamMetaData.php:134), and so does every ancestor reflected during matching. During cache:warmup:aop, and on large cache-miss requests, memory therefore grows with the AST of the whole codebase, and GC and the allocator slow down with it.

One reason the cache cannot simply be bounded today: WeavingTransformer::processSingleClass() reads the original imports through new ReflectionFileNamespace($classFileName, …) (src/Instrument/Transformer/WeavingTransformer.php:158). That call only avoids re-reading and re-parsing the file from disk because the AST cache happens to hit. It also takes the imports of the first block of that namespace when a file has several blocks of the same namespace.

Measurement

ReflectionEngine::parseFile($file, $content) over 3,931 vendor files (14 MB), PHP 8.5, JIT off:

cache time peak memory
unbounded (current) 7.35 s 671 MB
setMaximumCachedFiles(64) 5.5 s 68 MB
unbounded, GC disabled 6.3 s 671 MB
no retention at all (parse + NameResolver only) 4.8 s 31 MB

Proposal

  • In processSingleClass(), read the imports from the ReflectionFileNamespace already being iterated in transform(), and pass it down. This avoids the second ReflectionFileNamespace (two realpath calls plus a namespace lookup) and fixes the duplicate-namespace-block case.
  • Put a limit on the AST cache while weaving, for example setMaximumCachedFiles(256), set when the transformation pipeline is first brought up (SourceTransformingLoader::ensureRegistered()) and in CacheWarmer. Choose the limit by measurement: parents are re-used across files, so measure warmup with a limit of 64, 256 and 1024.
  • Optionally, evict the woven file's own AST once its transformation is finished.

Acceptance

  • Woven output unchanged.
  • A warmup benchmark (time and peak memory) for the chosen limit.
  • composer test:performance:transformation before and after: WeavingTransformer and the loader wiring are touched.

Estimate

About −20–25% parse time and about −90% peak memory during warmup. Low to medium risk, small change.

Lingua principale
PHP
Stelle
1.7k
Fork
166
Merge medio
9h 12m
PR unite (30g)
30

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di goaop/framework

Tutte le issue di goaop/framework

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.