Skip to content

[perf] Compare property name before anonymous-class reflection in PropertyFetchFinder - #8712

Merged
TomasVotruba merged 1 commit into
mainfrom
hoist-name-check-property-fetch-finder
Oct 19, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
hoist-name-check-property-fetch-finder

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

When findPropertyFetchesInClassLike() scans a class body for fetches of one property, each PropertyFetch node ran isInAnonymous() - which calls resolveClassReflection() - before the property name was compared. A class body references many different properties, so every fetch of an unrelated property paid for the anonymous-class reflection lookup only to fail the name check right after.

The property name is now compared first; on a mismatch it bails before isInAnonymous(). The outcome is unchanged: a name mismatch returned false either way (isNamePropertyNameEquals -> isLocalPropertyFetchByName rechecks the same name), and isInAnonymous() is a pure query with no side effect.

Full test suite passes (4988 tests).

Bench included (bench/property_fetch_finder_name_bench.php), scanning a class with 401 property fetches (only a couple match the target). CPU per scan, two runs each:

ms/scan
before ~4.9
after ~3.3-3.6

~1.4x faster. The finder runs in dead-code, privatization and readonly rules that scan class bodies for property usage.

@TomasVotruba
TomasVotruba merged commit 56954f6 into main Oct 19, 2026
48 of 49 checks passed
@TomasVotruba
TomasVotruba deleted the hoist-name-check-property-fetch-finder branch October 19, 2026 09:42
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.

1 participant