Skip to content

TAILLCALL VM: Do not return in ZEND_VM_ENTER_EX, ZEND_VM_LEAVE#21475

Open
arnaud-lb wants to merge 3 commits intophp:masterfrom
arnaud-lb:enter-tailcall
Open

TAILLCALL VM: Do not return in ZEND_VM_ENTER_EX, ZEND_VM_LEAVE#21475
arnaud-lb wants to merge 3 commits intophp:masterfrom
arnaud-lb:enter-tailcall

Conversation

@arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Mar 20, 2026

The TAILLCALL VM returns in ZEND_VM_ENTER_EX and ZEND_VM_LEAVE, but that's not necessary.

Redefine ZEND_VM_ENTER_EX, ZEND_VM_LEAVE so that they tailcall instead.

This makes the Symfony and bench.php benchmarks about 1% and 3.5% faster.

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

As I understood, this affects only TAILCALL VM.
So, it should be fine, except for a single minor comment.

out($f," } while (0)\n");
out($f,"# define ZEND_VM_DISPATCH_TO_LEAVE_HELPER(helper) opline = &call_leave_op; SAVE_OPLINE(); ZEND_VM_CONTINUE()\n");
out($f,"# define ZEND_VM_INTERRUPT() ZEND_VM_TAIL_CALL(zend_interrupt_helper".($spec?"_SPEC":"")."_TAILCALL(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU))\n");
out($f,"# define ZEND_VM_ENTER_EX() ZEND_VM_CONTINUE()\n");
Copy link
Member

Choose a reason for hiding this comment

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

This misses ZEND_VM_INTERRUPT_CHECK();, otherwise a deeply recursive function couldn't be interrupted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I forgot about this. In the CALL VM, ZEND_VM_ENTER_EX() relies on the interpreter loop to check for interrupts. Here we need to check interrupts in ZEND_VM_ENTER_EX() since we don't return to the loop anymore.

I've added ZEND_VM_INTERRUPT_CHECK(). Performance numbers are not impacted meaningfully.

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