Skip to content

Remove cache slot from ZEND_VERIFY_RETURN_TYPE and arg RECV opcodes - #18258

Merged
ndossche merged 1 commit into
php:masterfrom
ndossche:tmp-cache-slot-1
Apr 7, 2025
Merged

Remove cache slot from ZEND_VERIFY_RETURN_TYPE and arg RECV opcodes#18258
ndossche merged 1 commit into
php:masterfrom
ndossche:tmp-cache-slot-1

Conversation

@ndossche

@ndosschendossche commented Apr 5, 2025

Copy link
Copy Markdown
Member

Since #7336 the CE cache is always used even if Opcache is not loaded.
This means that the cache slot is almost fully redundant, except for self/parent/static. Removing this was hinted at in #7336 (review) but was never done. This patch removes this finally.

Valgrind in CI shows a I-count reduction of 0.13% without JIT and 0.08% with JIT for Symfony. 0.06% and 0.08% reduction for Wordpress respectively without and with JIT.

Real-time benchmarks on an i7-1185G7:

Symfony Benchmark (public/index.php)

Ran with -T 10,45

JITVersionMean Time (ms)Std Dev (ms)Min Time (ms)Max Time (ms)Speedup
DisabledOriginal PHP490.7±1.4488.3493.31.00×
DisabledPatched PHP486.4±1.3484.6488.81.01×
TracingOriginal PHP618.9±1.8617.2623.11.00×
TracingPatched PHP614.7±3.4610.6622.11.01×

WordPress Benchmark (index.php)

Ran with -T 5,20

JITVersionMean Time (ms)Std Dev (ms)Min Time (ms)Max Time (ms)Speedup
DisabledOriginal PHP637.8±2.7633.0641.81.00×
DisabledPatched PHP633.1±3.0630.3639.51.01×
TracingOriginal PHP763.3±4.0757.8770.81.00×
TracingPatched PHP758.2±3.7754.4766.21.01×

So I see very slight improvements and no regressions.
Note that tracing run has a higher baseline due to initial JIT overhead, but increasing the number of runs made the machine throttle which ruined the stability of the benchmark.

@ndosschendossche changed the title Remove cache slot from ZEND_VERIFY_TYPE and arg RECV opcodesRemove cache slot from ZEND_VERIFY_RETURN_TYPE and arg RECV opcodesApr 6, 2025
@iluuu1994

Copy link
Copy Markdown
Member

This is essentially redundant since adding the interned string CE cache, right?

@ndossche

Copy link
Copy Markdown
MemberAuthor

This is essentially redundant since adding the interned string CE cache, right?

Indeed. I'm currently benching and will update the OP when I have results.

@iluuu1994

iluuu1994 commented Apr 6, 2025

Copy link
Copy Markdown
Member

Nice simplification. We've briefly mentioned the possibility of adding a class cache for RECV and VERIFY_RETURN_TYPES in another issue. This would require a single slot, where the CE of the last value successfully type checked would be stored. This is mostly useful for union and intersection types, improving consecutive calls with the same class type. If there are concerns of slowing down non-union/intersection type checks, we could create a custom specialized handler that is only used when a cache slot is actually allocated. This might be worth exploring as well.

@ndossche

Copy link
Copy Markdown
MemberAuthor

Nice simplification. We've briefly mentioned the possibility of adding a class cache for RECV and VERIFY_RETURN_TYPES in another issue. This would require a single slot, where the CE of the last value successfully type checked would be stored. This is mostly useful for union and intersection types, improving consecutive calls with the same class type. If there are concerns of slowing down non-union/intersection type checks, we could create a custom specialized handler that is only used when a cache slot is actually allocated. This might be worth exploring as well.

That should be done separately from this PR.
Where can I find the discussion? Is it a situation that really occurs a lot in practice?

@ndossche
ndossche marked this pull request as ready for review April 6, 2025 11:53
@ndossche
ndossche requested a review from dstogov as a code ownerApril 6, 2025 11:53
@iluuu1994

Copy link
Copy Markdown
Member

#18189 (comment) mentions it. It would likely be a small optimization.

@ndossche

ndossche commented Apr 6, 2025

Copy link
Copy Markdown
MemberAuthor

#18189 (comment) mentions it. It would likely be a small optimization.

Oh right, I can take a look at that after this goes through. (The implementation and handling of cache slots would be different to this anyway)

@dstogovdstogov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can't do a deep review now, but since this removes more than adds, I support this.

@arnaud-lbarnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

This looks good to me.

@iluuu1994iluuu1994 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM as well

@ndossche
ndosscheforce-pushed the tmp-cache-slot-1 branch 2 times, most recently from 9a691fe to be0132eCompareApril 7, 2025 17:04
@ndossche
ndossche merged commit a32f491 into php:masterApr 7, 2025
Sign up for freeto 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.

4 participants

@ndossche@iluuu1994@arnaud-lb@dstogov