Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YJIT: Lazily enable YJIT after prelude #6597

Merged
merged 3 commits into from Oct 24, 2022
Merged

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Oct 20, 2022

Currently, YJIT compiles code for prelude as well. But some code used by prelude may not be used ever again after prelude, which could bring less localized code and unnecessary pressure on code GC.

JITing prelude seems just useless if it doesn't contribute to speeding up prelude. And the cost of JITing prelude seems to outweigh the JITed code's speedup. So I'd like to propose not JITing prelude.

Before

$ time ruby -v --yjit -e ''
ruby 3.2.0dev (2022-10-20T00:45:36Z master 2e3b764ad1) +YJIT [arm64-darwin21]
ruby -v --yjit -e ''  0.05s user 0.02s system 91% cpu 0.071 total

After

$ time ruby -v --yjit -e ''
ruby 3.2.0dev (2022-10-20T00:45:54Z yjit-lazy-init f60a1b4ce3) +YJIT [arm64-darwin21]
ruby -v --yjit -e ''  0.04s user 0.01s system 90% cpu 0.058 total

I've tried both multiple times, and this PR was reliably faster.

internal/cmdlineopt.h Outdated Show resolved Hide resolved
@k0kubun k0kubun requested a review from a team October 20, 2022 05:57
@noahgibbs
Copy link
Contributor

This looks like a good idea to me.

@maximecb
Copy link
Contributor

Just to make sure I understand, this enables YJIT after Ruby is done loading Ruby runtime code? Is that what you mean by prelude?

@noahgibbs
Copy link
Contributor

The prelude is the pre-loaded things like Rubygems which are loaded before the "real start" of the Ruby code in the file you specify (or equivalent -e param(s) to eval). So this won't affect e.g. Rails initialisers, they happen long after the prelude. But it will keep us from starting to JIT Rubygems' startup code, which seems like a good idea to me.

It would probably be an even better idea to have some way to not start JITting until an app-specified location, e.g. after Rails startup. But that would need more of an API. This has the advantage that it's really clear where to start.

@maximecb maximecb merged commit 120b747 into ruby:master Oct 24, 2022
@maximecb maximecb deleted the yjit-lazy-init branch October 24, 2022 16:20
tenderlove pushed a commit to Shopify/ruby that referenced this pull request Oct 27, 2022
* YJIT: Lazily enable YJIT after prelude

* Update dependencies

* Use a bit field for opt->yjit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants