Skip to content

[perf] Replace per-node config scan with keyed lookup in Rename func/const/string rules - #8736

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-perf-rename-keyed-lookup
Oct 20, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-perf-rename-keyed-lookup

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Follows #8734 / #8735. Three more configurable Renaming rules held a map already keyed by the value they match, yet scanned the whole map for every visited node.

rule was now
RenameFunctionRector isStringName() per entry over all func calls lookup by lowercased name (func names case-insensitive)
RenameConstantRector isName() per entry over all const fetches direct lookup by name (case-sensitive, matches PHP constant semantics)
RenameStringRector isValue() per entry over all string literals resolve value once, array lookup

These nodes (func calls, const fetches, string literals) are high frequency and upgrade sets configure hundreds of entries, so the per-node scan was a real linear cost.

Behaviour

Covered by the existing rule tests (all green). Note: the constant lookup is now case-sensitive, which is correct for PHP constants and consistent with how the rename writes the new name; the function lookup stays case-insensitive via lowercased keys.

Numbers

bench/rename_function_keyed_lookup_bench.php (500 renames, 200 non-matching calls, CPU time):

us/call
before 173.1
after 3.3

Scales with configured-map size. Full rules-tests/Renaming green, PHPStan and ECS clean.

…const/string rules

RenameFunctionRector, RenameConstantRector and RenameStringRector each held a map already keyed by the matched value, yet scanned the whole map per visited node (isStringName/isName/isValue per entry). Resolve the node name/value once and look the rename up directly.

- function: keyed by lowercased name (function names are case-insensitive), preserved.
- constant: case-sensitive direct lookup, matching PHP constant semantics.
- string: resolve the value once, then array lookup.

bench/rename_function_keyed_lookup_bench.php (500 renames, 200 non-matching calls): 173.1 -> 3.3 us/call.
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