Skip to content

perf(core): preloadFrameworkClasses() include_once's the entire library (~180 files) on every Core::init() #193

Description

@lisachenko

Problem

src/Core.php:1180-1193 (preloadFrameworkClasses()) recursively walks src/ with a RecursiveDirectoryIterator and include_onces every .php file (~180 files, plus the stat cost of the walk) on each Core::init() — including the ~55 ClassExtension hook interfaces a given consumer will never touch. It also runs again on a re-init() after shutdown().

The stated purpose (the "bypass all possible hooks" comment) is to ensure classes reachable from FFI hook trampolines are loaded without triggering autoloading mid-callback — a real constraint, but one that doesn't require the whole library.

Options

  1. Minimum: guard with the self::$initialized / a static $preloaded flag so re-init doesn't repeat the walk.
  2. Better: replace the directory walk with an explicit list (generated or hand-maintained + CI-checked) of the classes actually reachable from hook trampolines, and preload only those.
  3. Alternative: document opcache.preload (preload.php already exists) as the supported mechanism for production and reduce the runtime fallback to option 2's minimal set.

Numbers and call path verified during the 2026-08 modernization review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions