Performance: rewrite only the `new` expressions an `initialization(...)` pointcut can match

オープン
#833 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php

調査の方向性

Start with ConstructorExecutionTransformer and its $sourceMarkers logic, then trace how AdvisorIndex represents initialization pointcut class filters and how woven files track aspect and kernel resources. Add focused transformer tests for unrelated, matching, subclass, non-reducible, and dynamic new expressions; done means unrelated classes remain native while the existing initialization tests still pass. Compare transformation performance on a woven file with many unrelated constructions before and after.

索引モデルが issue の本文から書いたものです。

説明

Enhancement Performance

Split from #818, part 3 (the optional transformer prefilter). Parts 1–2 shipped in #828.

Problem

While at least one initialization(...) pointcut is registered, ConstructorExecutionTransformer rewrites every new Foo(...) in every woven file into ConstructorExecutionTransformer::construct(...). The rule is all-or-nothing: $sourceMarkers returns ['new'] as soon as AdvisorIndex::hasPointcutKind(Pointcut::KIND_INIT) is true. One initialization(App\Domain\Order) pointcut is enough to route the new of every class in the application through the transformer.

#828 made the runtime side cheaper: the per-class strategy cache, and a native new for instantiable classes without initialization advices. The remaining cost is still there for every rewritten new of an unrelated class.

new of a class no pointcut matches ns per new (PHP 8.5, JIT off)
native new ~64
rewritten, public constructor (after #828) ~193
rewritten, private/protected constructor, abstract, enum ~500 (still the advice-less ReflectionConstructorInvocation)

The rewrite also makes woven sources and stack traces noisier (an extra transformer frame per new).

Proposal

Rewrite only the new expressions whose class can match one of the registered initialization pointcuts, and keep the others native.

When the rewrite stays:

  • Resolve the class name of each new at transform time (the name resolver already runs).
  • Keep the rewrite for every new whose class can't be decided statically: new $class, new static, new self/new parent where the target is unknown, and anonymous classes as today.

Pointcut side: a small, conservative API.

  • The initialization class filters are namespace patterns: App\Domain\*, **, Foo|Bar.
  • A filter like Foo+ also matches subclasses and can't be decided by name. The same goes for an expression combined with other pointcuts in a way that can't be reduced to class-name patterns (!, && with within(...), references).
  • A pointcut of that kind answers "may match anything", and the transformer then keeps rewriting every new, as today.
  • Compare #747 and #821, which hit the same need for a name-part API.

Caching: the decision belongs to the woven file. A changed set of initialization pointcuts must re-weave affected files. Check that aspect and kernel changes already invalidate woven files through the tracked resources, the same way any advice change does.

Acceptance

  • With an unrelated initialization(...) pointcut registered, new of a class that can't match stays a native new in the woven source: snapshot or unit test on ConstructorExecutionTransformer.
  • Classes that can match, + subclass filters, non-reducible expressions and dynamic new keep the current rewrite, with identical behaviour in the existing initialization tests.
  • A benchmark of a woven file with many new of unrelated classes, before and after.
  • composer test, composer analyze, composer test:performance:transformation (the transformer changes, so CI compares head with base).

Scoring

Score Why
Effort Medium A pointcut-side "class name may match" API that is conservative for +, !, && and references, plus the per-new decision in the transformer, snapshot tests and the transformation-performance run. No runtime or format change.
Impact Low–Medium Applications without initialization(...) pointcuts gain nothing. With one, every new of an unrelated class saves ~130 ns, or ~430 ns for classes with a non-public constructor, abstract classes and enums, and woven sources lose the extra frame. It only matters for code that creates many objects in woven files.

Priority Low: #828 already removed most of the cost on the hot path.

主要言語
PHP
スター
1.7k
フォーク
166
平均マージ
1日 1時間
マージ済み PR(30日)
42

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

goaop/framework のほかの issue

goaop/framework の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。