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

Performance: skip the syntax-tree rewrite walk for files no rule can affect

Chiusa
#736 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
30/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
php
Ambito
performance

Direzione di ricerca

Start from SyntaxTreeRewriter::transform(), which walks every transformed file, and NodeRewriterDispatcher, which resolves rules per node class through a closure into getRulesFor(). The proposal adds an optional way for a NodeRewriter (e.g. MagicConstantTransformer) to declare cheap source substrings, then skips the walk when none match. Measure with composer test:performance:transformation, JIT off; done means the rewrite ratio drops while a rule declaring no substrings still always applies.

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

Descrizione

Enhancement Performance

Problem

SyntaxTreeRewriter walks the whole syntax tree of every transformed file, even when none of the enabled rules can match it. The visitor also finds the rules for each node through a closure call into SyntaxTreeRewriter::getRulesFor().

Measurement

composer test:performance:transformation (JIT off), php-parser corpus of 271 files:

ms
parse (the main cost of a cache miss) ~252
plain walk with a no-op visitor ~26
SyntaxTreeRewriter, default rules ~42 (ratio 1.54)
SyntaxTreeRewriter, all rules ~44 (ratio 1.67)
str_contains pre-check over all sources 0.4
  • Only 14 of 271 files contain __DIR__, __FILE__ or getFileName, which the default MagicConstantTransformer rule looks for. Only 16 contain include or require, and 78 contain new.
  • Caching the rule list per node class inside NodeRewriterDispatcher alone moved the ratios from 1.53 to 1.42–1.47 (default rules) and from 1.70 to 1.49–1.58 (all rules).

Proposal

  • Let a rule declare cheap source substrings that must appear for it to apply, through an optional method or interface. Keep the NodeRewriter contract compatible for custom rules: a rule without substrings always applies.
  • SyntaxTreeRewriter::transform() skips the walk when no enabled rule's substrings appear in the source, and walks with only the rules whose substrings do.
  • Inline the rule lookup per node class in NodeRewriterDispatcher.

Estimate

Cache misses only. With the default rules about 95% of files skip the walk, which saves about 13% of parse plus rewrite time on cache warm-up and debug-mode re-transformations. The rule lookup alone saves 5–8% of the rewriter time. Medium risk (the public NodeRewriter API is touched), medium effort, best done before 4.0.0.

Lingua principale
PHP
Stelle
1.7k
Fork
166
Merge medio
9h 50m
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.