Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Bootstrap loads every class eagerly; rely on the classmap from #526 instead

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

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php, wordpress

調査の方向性

Examine agents-api.php to see the current eager require_once statements. Identify the files with side effects (register-.php, functions-.php, guidelines.php) and the add_action calls. Understand the Composer classmap from PR #526. Test changes in a WordPress multisite setup, using opcache_get_status() to measure memory impact. Ensure version skew handling via AGENTS_API_LOADED is preserved.

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

説明

Problem

agents-api.php require_onces every class and interface file under src/ (about 240 files on current main, 0.11.2) on every request, before any agent, chat or workflow is used. #526 added a lazy Composer classmap covering the full public class/interface surface, but the bootstrap still loads all of those classes eagerly, so the classmap never gets a chance to be lazy at runtime.

On a WordPress multisite where the package is bundled in a network-activated plugin (via Composer, as wordpress/agents-api), the package accounts for 249 cached scripts and about 5 MB of OPcache memory, measured with opcache_get_status(). On that server OPcache is full (128 MB), so this is memory taken from code that runs on every request. The chat is used on one page; every other request on every site pays for the whole runtime.

Proposal

Now that every class and interface is in the classmap, the bootstrap only needs to require_once files that have side effects or define functions:

  • src/*/register-*.php
  • src/Runtime/functions-*.php, src/Abilities/functions-ability-dispatch.php, src/Guidelines/guidelines.php
  • the add_action() calls at the end

and leave class-*.php / interface-*.php to the autoloader. Hook callbacks already reference classes by name as strings, so registration itself should not force them to load. Only a class actually touched during a request would be compiled and cached.

For the non-Composer (plain plugin) install, a small spl_autoload_register() over a generated class-to-file map (or the existing vendor/composer/autoload_classmap.php) would give the same behaviour.

Things to keep

  • Version skew. The AGENTS_API_LOADED branch currently loads missing symbols from the newer copy eagerly. With lazy loading, whichever copy's autoloader is registered first would win for classes not yet loaded, so the skew guarantee from #279 needs an equivalent (for example, the bootstrap that defines AGENTS_API_LOADED registering its own class map ahead of Composer's, or the skew branch registering a prepend autoloader for the newer copy).
  • Composer autoload outside WordPress stays inert, and PHPStan behaviour from #524/#526 is unchanged.

Happy to test a branch against our install and report OPcache numbers before and after.

主要言語
PHP
スター
33
フォーク
8
平均マージ
24分
マージ済み PR(30日)
18

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

Automattic/agents-api のほかの issue

Automattic/agents-api の issue をすべて見る

似ている issue

PHP の issue をもっと見る

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

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