Skip to content

[perf] Key config by method/property name in Add*Type rules - #8744

Open
TomasVotruba wants to merge 1 commit into
mainfrom
tv-perf-addtype-bucket
Open

TomasVotruba wants to merge 1 commit into
mainfrom
tv-perf-addtype-bucket

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Batch D of the configurable-rule config-scan cleanup (follows #8734 / #8735 / #8736 / #8739 / #8742 / #8743). Three TypeDeclaration rules scanned their whole configured list per visited node, running isName() / isStringName() on each entry before the class/object-type check.

rule node key
AddParamTypeDeclarationRector Class_ / Interface_ method
AddPropertyTypeDeclarationRector Property property
AddReturnTypeDeclarationRector Class_ method

Each builds a bucket keyed by lowercased old name once in configure(), so a node only visits the entries sharing its name; the class / object-type check stays inside the matched branch. AddReturnTypeDeclarationRector drops its per-node classMethodNames presence hash and full config scan, iterating the class methods and looking each up in the bucket. The lowercased key matches the case-insensitive isName() these rules already used, so behaviour is unchanged.

Numbers

bench/add_property_type_bucket_bench.php (400 entries, 150 non-matching properties, CPU time):

us/call
before 1063.7
after 2.4

Scales with configured-list size. AddParamTypeDeclarationRector / AddPropertyTypeDeclarationRector / AddReturnTypeDeclarationRector tests (18) green, PHPStan and ECS clean.

AddParamTypeDeclarationRector, AddPropertyTypeDeclarationRector and AddReturnTypeDeclarationRector each scanned their whole configured list per visited node, running isName()/isStringName() per entry before the class/object-type check. Bucket the list by lowercased old name once in configure(), so a node only visits the entries sharing its name.

AddReturnTypeDeclarationRector dropped its per-node classMethodNames presence hash + full config scan in favour of iterating the class methods and looking each up in the bucket.

The lowercased key matches the case-insensitive isName() lookup these rules already used, so behaviour is unchanged.

bench/add_property_type_bucket_bench.php (400 entries, 150 non-matching properties): 1063.7 -> 2.4 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