Skip to content

ZJIT: Specialize invokeblock for each block_handler type #855

@k0kubun

Description

@k0kubun

At the moment, invokeblock always resorts to dynamic dispatch, but JIT code can do better.

There are four vm_block_handler_types:

  1. block_handler_type_iseq
  2. block_handler_type_ifunc
  3. block_handler_type_proc
  4. block_handler_type_symbol

TODO

  • We should profile block_handler on invokeblock and generate specialized code based on compile-time block_handler. It's also nice to have runtime stats to prioritize the most frequent block_handler. YJIT doesn't specialize block_handler_type_proc or block_handler_type_symbol, so majority of them would be block_handler_type_iseq or block_handler_type_ifunc in our benchmarks and production.
  • If compile-time block_handler is block_handler_type_iseq, you can guard on the expected ISEQ in the block_handler and statically dispatch the callee ISEQ using a JIT-to-JIT call.
  • If compile-time block_handler is block_handler_type_ifunc, you can just guard the block_handler type is ifunc (blocks in C), and let rb_vm_yield_with_cfunc call the ifunc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions