Skip to content

Instantly share code, notes, and snippets.

@zonuexe
Last active July 10, 2022 02:08
Show Gist options
  • Save zonuexe/e8cb1436478c18531acdc7330b9f96d2 to your computer and use it in GitHub Desktop.
Save zonuexe/e8cb1436478c18531acdc7330b9f96d2 to your computer and use it in GitHub Desktop.
Qiitaコメント (deleted)

気になっているポイントとしては二つあって、

  • OPCacheは考慮しているか
  • 10万ファイルや10万メソッドのアプリケーションを使うことは本当にあるのか

前者はぐぐればわかると思うので割愛しましょう。SafePHPというライブラリはBlackfireというPHPでもっとも信頼が置かれているパフォーマンス計測ツールで計測し、1000以上のファイルを84ファイルに分割して配置してもパフォーマンスの影響は700マイクロ秒程度だと結論付けています。

後者についてですが、Laravelのインストール直後で、デフォルトのトップページを表示読み込みファイル数/クラス数/関数数/合計メソッド数を数えてみましょう。

var_dump([
    'get_included_files' => count(get_included_files()),
    'get_declared_classes' => count(get_declared_classes()),
    'get_defined_functions' => array_sum(array_map(count(...), get_defined_functions())),
    'defined_methods' => array_sum(array_map(fn ($class) => count(array_merge(get_class_methods($class))), get_declared_classes())),
]);
Laravel v9.19.0 (PHP v8.1.8)
array(2) {
    ["get_included_files"]=> int(457)
    ["get_declared_classes"]=> int(552)
    ["get_defined_functions"]=> int(2503)
    ["defined_methods"]=> int(10110)
}

アプリケーションの実装やライブラリを増やしても、数としてはたかだか倍くらいなのではないでしょうか。 (僕も残りの人生で書く新規クラスは1万に届くか、きっと届かなさそう)

実際に存在しないユースケースのための最適化が施されることないので、実際にありえる数で計測すると良いのではないでしょうか。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment