-
Notifications
You must be signed in to change notification settings - Fork 14
ZJIT: Optimize send with nil block arg to SendDirect #969
Copy link
Copy link
Open
ruby/ruby
#16621Description
When a send has ARGS_BLOCKARG and the block arg is nil (either statically known or profiled as monomorphically nil), we can strip the block arg and optimize the call to SendDirect without a block.
This reduces the param_block category in the complex argument-parameter fallback stats (34.2% of total on lobsters as of the burndown in #833).
Implementation
- Profile the block arg alongside self and regular args for
sendinstructions - If the block arg type is statically
NilClassor profiled as monomorphically nil, strip it and emitSendDirectwithout a block - Insert a
GuardBitEqualsside exit when relying on profiled (not static) nil - Update the frame state snapshot after stripping to keep SP consistent in codegen
Bug fix
The initial implementation had a stack consistency error (sp: N+1, bp: N) when the guard side-exited for a non-nil block. The frame state snapshot still contained the stripped block arg, causing gen_save_sp to compute the wrong SP. Fixed by creating a new snapshot with the block arg removed.
Related: #833 (lobsters perf burndown)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.