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

Performance: proxy generators print, re-parse and re-print every generated method body

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

Direzione di ricerca

Read the listed entry points in InterceptorListGenerator.php, MethodGenerator.php, FunctionGenerator.php, the proxy generators, WeavingTransformer.php, and AttributeGroupsGenerator.php; compare them with the AST-based hooks in InterceptedPropertyGenerator. Run the weaving fixture snapshot tests and composer test:performance:transformation before and after. Done means snapshots remain byte-identical, DebugWeavingCommand has no warm-up differences, and the benchmark confirms the performance change.

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

Descrizione

Enhancement Performance

Problem

Generating the body of each intercepted method or function takes a lex, an LR parse and two pretty-prints:

  1. new InterceptorListGenerator(...)->generate() creates a new GeneratedCodePrinter per call (src/Proxy/Generator/InterceptorListGenerator.php:97) and prints the interceptor list to a string. Call sites:
    • ClassProxyGenerator.php:353, 409, 434
    • EnumProxyGenerator.php:243
    • TraitProxyGenerator.php:157
    • FunctionProxyGenerator.php:132
  2. The string is put into a heredoc body. The setter parses that string back into an AST: self::getParser()->parse('<?php ' . $value) in MethodGenerator.php:103 and FunctionGenerator.php:79.
  3. ClassGenerator and FunctionGenerator then print the whole class or function again.

Smaller work is also repeated per intercepted method:

  • Linear method lookups: parser-reflection's hasMethod() and getMethod() scan all methods. They are called several times per intercepted method: WeavingTransformer.php:594, 598, ClassProxyGenerator.php:123 (twice), :219, :273, and the same in the Enum and Trait generators. That is O(k·M) scans for a class with k intercepted methods out of M.
  • Wasted type render: ClassProxyGenerator.php:354 renders the return type through reflection with TypeGenerator::renderTypeForPhpDoc($method->getReturnType()), then :356-362 overwrites it from the AST node, which always exists during weaving. The same AST → ReflectionType → AST round trip happens for parameter and return types in MethodGenerator and ParameterGenerator, although TypeGenerator::fromAstNode() exists.
  • Attribute copying: AttributeGroupsGenerator.php:181-198 builds a new NodeTraverser with an anonymous visitor class for every copied attribute, even one without arguments. The anonymous class also breaks the AGENTS.md rule "no anonymous classes in src/".

Proposal

  • Method bodies: build them as AST directly. That means a Static_ statement for $__joinPoint with its @var doc comment, the InterceptorInjector::for*() call built from InterceptorListGenerator::getNode(), and a Return_ or Expression for the __invoke. The generators then set statements instead of a code string. InterceptedPropertyGenerator already builds its hooks this way, and GeneratedCodePrinter already produces the multi-line layout from the AST.
  • Method lookups: build a name → method map once per woven class and share it between WeavingTransformer and the generators.
  • Types: take the AST path first and fall back to reflection only when no node is available.
  • Attributes: use a named final @internal visitor, created once, and skip the traversal when the attribute has no arguments.

Acceptance

  • Generated proxies stay byte-identical: the existing snapshot tests of the weaving fixtures, and the double warm-up of DebugWeavingCommand stays free of differences.
  • composer test:performance:transformation before and after: the weaving case covers proxy generation.

Estimate

Roughly 30–50% of proxy-generation time per intercepted method (estimate from reading the code, to be confirmed by the weaving benchmark). Low to medium risk, medium change.

Lingua principale
PHP
Stelle
1.7k
Fork
166
Merge medio
19h 39m
PR unite (30g)
48

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.