Skip to content

Conversation

@chancancode
Copy link
Contributor

This implements Shopify#854:

  • Splits boot-time and enable-time initialization, tracks progress with InitializationState enum

  • Introduces RubyVM::ZJIT.enable Ruby method for enabling the JIT lazily, if not already enabled

  • Introduces --zjit-disable flag, which can be used alongside the other --zjit-* flags but prevents enabling the JIT at boot time

  • Adds ZJIT infra to support JIT hooks, but this is not currently exercised (ZJIT: Allow ZJIT to use #with_jit hooks Shopify/ruby#667)

Left for future enhancements:

  • Support kwargs for overriding the CLI flags in RubyVM::ZJIT.enable

Closes Shopify#854


/// Enable ZJIT compilation.
fn zjit_enable() {
// TODO: call RubyVM::ZJIT::call_jit_hooks here
Copy link
Contributor Author

@chancancode chancancode Nov 18, 2025

Choose a reason for hiding this comment

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

Happy to fill this in here, but not sure what is the approach we want to use here.

The yjit equivalent does this:

let yjit = rb_const_get(rb_cRubyVM, rust_str_to_id("YJIT"));
rb_funcall(yjit, rust_str_to_id("call_jit_hooks"), 0);

We have rb_funcallv in zjit, I suppose I could bind rb_cRubyVM and rb_const_get and make it work, just want to get someone else's opinion before I do that.

Alternatively, since this code will remain dormant anyway until Shopify#667 is resolved, we could also punt for now.

Copy link
Member

@k0kubun k0kubun Nov 18, 2025

Choose a reason for hiding this comment

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

We have rb_funcallv in zjit, I suppose I could bind rb_cRubyVM and rb_const_get and make it work, just want to get someone else's opinion before I do that.

Yeah, I think that's what we want to do. I don't come up with any better way.

@chancancode chancancode force-pushed the zjit-enable branch 4 times, most recently from 37c559f to 82d7dac Compare November 18, 2025 07:36
This implements Shopify#854:

- Splits boot-time and enable-time initialization,
  tracks progress with `InitializationState` enum

- Introduces `RubyVM::ZJIT.enable` Ruby method for
  enabling the JIT lazily, if not already enabled

- Introduces `--zjit-disable` flag, which can be
  used alongside the other `--zjit-*` flags but
  prevents enabling the JIT at boot time

- Adds ZJIT infra to support JIT hooks, but this
  is not currently exercised (Shopify#667)

Left for future enhancements:

- Support kwargs for overriding the CLI flags in
  `RubyVM::ZJIT.enable`

Closes Shopify#854
Copy link
Member

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@k0kubun k0kubun merged commit f84bbb4 into ruby:master Nov 18, 2025
89 checks passed
@chancancode chancancode deleted the zjit-enable branch November 18, 2025 17:20
@chancancode
Copy link
Contributor Author

chancancode commented Dec 25, 2025

Support kwargs for overriding the CLI flags in RubyVM::ZJIT.enable

Shopify#923

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZJIT: Support enabling ZJIT lazily with RubyVM::ZJIT.enable

2 participants