rvm icon indicating copy to clipboard operation
rvm copied to clipboard

Add support for ruby-yjit

Open brodock opened this issue 2 years ago • 23 comments

Description

Support the experimental YJIT branch from Shopify: https://shopify.engineering/yjit-faster-rubying.

It is currently available on ruby-build: https://github.com/rbenv/ruby-build/blob/9d3992be66ce10d4367cdf63923930384c78a771/share/ruby-build/yjit-dev

brodock avatar Oct 19 '21 16:10 brodock

We would welcome a PR for this feature...

pkuczynski avatar Oct 19 '21 17:10 pkuczynski

I don't think there's a need for a separate entry.

1/ it's going to be merged to the main repository very soon, after that, you'll be able to test it with rvm install ruby-head see https://github.com/ruby/ruby/pull/4992

2/ or you can use a custom remote repository

rvm install ruby-head-yjit --branch main --url https://github.com/Shopify/yjit.git

ahorek avatar Oct 20 '21 17:10 ahorek

Depends if you want bleeding edge YJIT or not. We'll continue our development in Shopify/yjit and the upstream will be a bit more stable.

maximecb avatar Oct 20 '21 18:10 maximecb

maybe provide an easy option to have both install for easy switching and testing ?

mathieujobin avatar Feb 03 '22 10:02 mathieujobin

I guess, the only thing you have to do is to make sure you have rust installed brew install rust and then rvm install 3.2.0 --reconfigure --enable-yjit.

tisba avatar Dec 25 '22 16:12 tisba

has this changed for Ruby 3.2 ? with 3.1, its enabled by default as far as compilation goes. you need to set an ENV var to true, RUBY_YJIT_ENABLE

Shell/Bash

export RUBY_YJIT_ENABLE=true

Docker

ENV RUBY_YJIT_ENABLE true

mathieujobin avatar Dec 26 '22 01:12 mathieujobin

hmm, to clarify @mathieujobin, you need to set those vars when compiling Ruby 3.2.0 from source, right? Maybe I'm missing something, but YJIT was not enabled for me when I build 3.2.0 🤔

tisba avatar Dec 27 '22 11:12 tisba

at runtime...

$ ruby -e 'puts RUBY_DESCRIPTION'
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
$ RUBY_YJIT_ENABLE=true ruby -e 'puts RUBY_DESCRIPTION'
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) +YJIT [x86_64-linux]

$ ruby -e 'puts RUBY_DESCRIPTION'
ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux]
$ RUBY_YJIT_ENABLE=true ruby -e 'puts RUBY_DESCRIPTION'
ruby 3.2.0 (2022-12-25 revision a528908271) +YJIT [x86_64-linux]

I did nothing at compile time, just rvm install 3.2

mathieujobin avatar Dec 28 '22 03:12 mathieujobin

I didn't have it on Debian 11 using the default commands. With @tisba's method of adding --enable-yjit it worked.

darkBuddha avatar Dec 28 '22 12:12 darkBuddha

By the way, how do you specify rustc edition explicily?

rvm install 3.2.0 -C "--enable-yjit"

enable you to build with Rust YJIT, but it also causes(rustc 1.63.0+dfsg1-1):

compiling dmyenc.c
building Rust YJIT (release mode)
error: argument for `--edition` must be one of: 2015|2018. (instead was `2021`)

kenhys avatar Jan 03 '23 12:01 kenhys

@kenhys this was fixed for me on Debian 11 by installing the latest Rust: https://www.rust-lang.org/tools/install

YJIT performance improvement on Raspberry Pi 4 is super impressive.

darkBuddha avatar Jan 03 '23 12:01 darkBuddha

@darkBuddha Thanks, it works.

% ruby --yjit -v
ruby 3.2.0 (2022-12-25 revision a528908271) +YJIT [x86_64-linux]

kenhys avatar Jan 03 '23 12:01 kenhys

I tried today, and was surprised to find that the binary wasn't compiled with yjit.

15:09 $ rvm install 3.2
Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/ubuntu/20.04/x86_64/ruby-3.2.0.tar.bz2
...
15:11 $ ruby --yjit -v
ruby: warning: Ruby was built without YJIT support. You may need to install rustc to build Ruby with YJIT.
ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux]

Is there an alternative binary that rvm can install that has yjit baked in?

botandrose avatar Jan 17 '23 21:01 botandrose

As the warning says... you need rustc preinstalled

mathieujobin avatar Jan 23 '23 11:01 mathieujobin

Yes, to compile Ruby with YJIT from source, rust is required. But rust isn't required to run Ruby with YJIT, and rvm prefers to install precompiled binaries when it can. I was expecting that the precompiled 3.2 binaries that rvm is pointing to would have YJIT support compiled in, but it seems they don't. My question is whether it's possible to point to other binaries that do, and perhaps even whether or not this should be considered a bug in rvm, and therefore changed for everyone.

botandrose avatar Jan 23 '23 14:01 botandrose

oh, they have resumed building precompiled binaries? That's good news.

I agree with you, the precompiled binaries for 3.1 and 3.2+ should have YJIT support built-in

mathieujobin avatar Jan 24 '23 00:01 mathieujobin

Any updates on this? Just did rvm install ruby-3.2.1 and was sad to see no YJIT support. Since I'm building a liquid-heavy site, YJIT does speed up my builds considerably...

khemarato avatar Aug 18 '23 11:08 khemarato

@buddhist-uni Does it work if you do export RUBY_CONFIGURE_OPTS="--enable-yjit" before rvm install ?

maximecb avatar Aug 18 '23 17:08 maximecb

Huzzah! Thanks, @maximecb That did it 😺

khemarato avatar Aug 18 '23 21:08 khemarato

Bumping because rvm is still not shipping pre-compiled binaries with YJIT enabled. That would be ideal.

gvkhna avatar Aug 18 '23 21:08 gvkhna

Bumping because still not available in prebuilt binaries for 3.3

botandrose avatar Feb 06 '24 20:02 botandrose

@botandrose prebuilt binaries is per platform. it might have been enabled for one platform but not the other. Please be more precise which binary is missing YJIT support

mathieujobin avatar Feb 22 '24 08:02 mathieujobin

@mathieujobin Ah, it looks like the situation has changed!

micah@yupa:~$ rvm install ruby-3.3.0
Found remote file https://rubies.travis-ci.org/ubuntu/22.04/x86_64/ruby-3.3.0.tar.bz2
[snip]
micah@yupa:~$ ruby --yjit -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [x86_64-linux]

Very happy to see this!

botandrose avatar Feb 22 '24 13:02 botandrose