Skip to content

perf(engine): create the parser and the name resolver on the first parse (4.x) - #239

Merged
lisachenko merged 2 commits into
4.xfrom
perf/lazy-parser-4.x
Oct 5, 2026
Merged

lisachenko merged 2 commits into
4.xfrom
perf/lazy-parser-4.x

Conversation

@lisachenko

Copy link
Copy Markdown
Member

What and why

Backport of #238 to the 4.x branch, which serves PHP 8.4 installs. Part of goaop/framework#730.

The composer files bootstrap runs ReflectionEngine::init() on every request, and init() built the PHP-Parser parser, lexer and name-resolving traverser right away. Now init() only stores the locator and grammar version, and getParser() / parseFile() create them on first use. ComposerLocator stays eager, because it must capture composer's ClassLoader before other loaders wrap it. That saves about 145 µs per warm request, measured on master with PHP 8.5 and opcache.

The commit is a clean cherry-pick of the master change, including the new tests/ReflectionEngineTest.php.

Tests

  • Full suite on this branch: 13747 tests OK (133 skipped, 2 incomplete). vendor/bin/phpstan analyse src: no errors.
  • Caveat: I ran this locally on PHP 8.5 with the master branch's installed dependencies. The 4.x CI matrix (PHP 8.4, lowest/highest) is the authoritative run.

🤖 Generated with Claude Code

https://claude.ai/code/session_019bYFRwMWKndKaj6SemwDn2


Generated by Claude Code

claude added 2 commits October 4, 2026 23:16
The composer "files" bootstrap of this package calls ReflectionEngine::init()
on every request of an application that installs it, and init() built the
PHP-Parser parser, lexer and name resolving traverser right away. Most
requests never parse anything: in goaop/framework, parsing only happens on
a cache miss.

init() now only stores the locator and the grammar version, getParser()
and parseFile() create the parser and the traverser on first use. The
ComposerLocator stays eager on purpose: it must find composer's own class
loader before other loaders wrap it.

Warm request with opcache (built-in server, median of 200): requiring
vendor/autoload.php of goaop/framework takes 87-91 instead of 229-242 µs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019bYFRwMWKndKaj6SemwDn2
… master

PHP 8.6 native reflection prints boolean constant values as "true" and
"false" instead of the string casts "1" and "", so the experimental
PHP 8.6 jobs of 4.x fail ReflectionClassTest::testGetReflectionConstant.
Ported from the same rendering on master, with its PHPStan ignores for
releases that do not know PHP 8.6 yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019bYFRwMWKndKaj6SemwDn2

Copy link
Copy Markdown
Member Author

The experimental PHPUnit tests (8.6, lowest/highest) jobs failed in ReflectionClassTest::testGetReflectionConstant: PHP 8.6 now prints boolean constants as { false }, and 4.x printed { }. This comes from the PHP 8.6 runtime, not from the lazy parser: the last 4.x run (August 25) was green, and nothing in this PR touches constant rendering.

Master already handles it, so 2c6b46b ports only that rendering (true/false on PHP ≥ 8.6) and master's two PHPStan ignores to 4.x. The doc-comment prefix master added at the same place is left out. The new run on 2c6b46b will show whether the 8.6 jobs pass.


Generated by Claude Code

@lisachenko
lisachenko marked this pull request as ready for review October 5, 2026 13:25
@lisachenko
lisachenko merged commit 9cd97a1 into 4.x Oct 5, 2026
7 checks passed
@lisachenko
lisachenko deleted the perf/lazy-parser-4.x branch October 5, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants