Skip to content

[perf] Read asserted class name off node in RemoveDeadInstanceOfAssertRector - #8726

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-instanceof-assert-name-type
Oct 20, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-instanceof-assert-name-type

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The rule drops assert($x instanceof Foo) when $x is already of type Foo. To get the asserted class type it read getType($instanceof->class), which runs the type resolver over a class name node whose name is already known.

A concrete class name is read straight off the node as new ObjectType($name); the equals()/isSuperTypeOf() comparison against the expression type is unchanged, so the decision is identical. self/static/parent depend on the enclosing class, so those fall back to getType().

Bench bench/remove_dead_instanceof_assert_name_type_bench.php over 9000 refactor() calls:

  • before: 18.83 us/call
  • after: 15.71 us/call (~1.2x)

Added skip_self_instanceof fixture to pin the self fallback path (unchanged, matches current behaviour).

@TomasVotruba
TomasVotruba merged commit ada148e into main Oct 20, 2026
48 of 49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-instanceof-assert-name-type branch October 20, 2026 10:43
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