Skip to content

Elide the type check on typed property writes when the value type is statically proven#22347

Open
azjezz wants to merge 3 commits into
php:masterfrom
carthage-software:elide-typed-prop-write-check
Open

Elide the type check on typed property writes when the value type is statically proven#22347
azjezz wants to merge 3 commits into
php:masterfrom
carthage-software:elide-typed-prop-write-check

Conversation

@azjezz

@azjezz azjezz commented Jun 16, 2026

Copy link
Copy Markdown

Assigning to a typed property runs zend_assign_to_typed_prop() on every write, a zend_never_inline call that verifies (and may coerce) the value against the property type. When the optimizer can already prove the value satisfies the property type with no coercion, that check is pure overhead.

This is extremely common: constructor property promotion, plain $this->x = $x from typed parameters, and fluent setters all hit it on every call. Neither the DFA optimizer nor the JIT elided it before.

Signed-off-by: azjezz <azjezz@protonmail.com>
@azjezz azjezz force-pushed the elide-typed-prop-write-check branch from 1bbd75c to faa7adc Compare June 16, 2026 22:45
Signed-off-by: azjezz <azjezz@protonmail.com>
Comment on lines 14900 to +14997
@@ -14989,7 +14994,7 @@ static int zend_jit_assign_obj(zend_jit_ctx *jit,
ir_END_list(slow_inputs);
ir_IF_TRUE(if_def);
}
if (ZEND_TYPE_IS_SET(prop_info->type)) {
if (ZEND_TYPE_IS_SET(prop_info->type) && !skip_type_check) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't verify this locally. and honestly not sure about it..

Signed-off-by: azjezz <azjezz@protonmail.com>
@azjezz azjezz marked this pull request as ready for review June 16, 2026 23:07
@azjezz azjezz requested a review from dstogov as a code owner June 16, 2026 23:07
@TimWolla TimWolla requested a review from iluuu1994 June 17, 2026 06:07
@mvorisek

Copy link
Copy Markdown
Contributor

This PR implements #13100.

I am suprised this PR only improves the performance by 0.04% on Symfony demo. I would expect more performance gain. Does this PR really drops most of the type checks?

@azjezz

azjezz commented Jun 18, 2026

Copy link
Copy Markdown
Author

@mvorisek Sorry did not see the open issue for this!

As for Symfony, honestly no idea, haven't benchmarked it. It does remove type checks for cases that i have tested.

@iluuu1994

Copy link
Copy Markdown
Member

I agree, a statistic of how many type checks in something like Symfony Demo can be elided would be nice. The instruction count difference is effectively nonexistent, so maybe it doesn't work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants