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: Add counter to measure how often we compile "cold" ISEQs #535

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

maximecb
Copy link

@maximecb maximecb commented Sep 14, 2023

I'd like to deploy this to Core so we can monitor the percentage of cold ISEQ entries that get compiled over the weekend.

The thresholds chosen are hardcoded, which is slightly hacky and just for this experiment, but they are set such that our largest benchmark (lobsters) has a small percentage ~2.9% of "cold" ISEQs only, with the idea that a much larger app should have a larger percentage of cold entries compiled, just because it has so much more code.

The idea being: maybe we can find heuristics that are set such that our benchmarks see no performance difference, the same amount of code gets compiled, but real production deployments benefit from less cold and rarely executed code being compiled.

@maximecb maximecb merged commit 5cde049 into v3.2.2-pshopify15-experimental2 Sep 14, 2023
124 of 168 checks passed
@maximecb maximecb deleted the yjit_entry_cold_backport branch September 14, 2023 20:28
@@ -429,7 +429,7 @@ jit_compile(rb_execution_context_t *ec)
if (body->jit_entry == NULL) {
body->jit_entry_calls++;
if (yjit_enabled) {
if (body->jit_entry_calls == rb_yjit_call_threshold()) {
if (rb_yjit_threshold_hit(iseq, body->jit_entry_calls)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you want to make this change to jit_compile_exception as well.

Copy link
Member

Choose a reason for hiding this comment

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

pushed 1c0d2a2

Copy link
Author

Choose a reason for hiding this comment

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

Eventually probably yes, but for now I would just like to see how the numbers come out for ISEQ entries.

Copy link
Author

Choose a reason for hiding this comment

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

No this will mess with the numbers, the ratio being computed is in relation to the number of entries we compile...

Copy link
Author

Choose a reason for hiding this comment

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

Reverting for now.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, sorry about that.

Copy link
Member

@k0kubun k0kubun Sep 14, 2023

Choose a reason for hiding this comment

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

Note that compiled_iseq_entry counts both normal entries and exception entries, so with this patch, you can't calculate the ratio of compiled_entry_cold entries relative to what this rb_yjit_threshold_hit targets, though.

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, I thought it didn't. It won't be fully accurate if we call rb_yjit_threshold_hit in both places either though 🤔

I guess let's just live with this inaccuracy for now. I'm assuming that exception entries are a small percentage overall. If the number is high enough for this kind of optimization to be interesting, we'll figure out how to implement this properly for Ruby master.

maximecb added a commit that referenced this pull request Sep 28, 2023
Fix counter name in DEFAULT_COUNTERS

YJIT: add --yjit-cold-threshold, don't compile cold ISEQs

YJIT: increase default cold threshold to 200_000

Remove rb_yjit_call_threshold()

Remove conflict markers

Fix compilation errors

Threshold 1 should compile immediately
maximecb added a commit that referenced this pull request Oct 2, 2023
Fix counter name in DEFAULT_COUNTERS

YJIT: add --yjit-cold-threshold, don't compile cold ISEQs

YJIT: increase default cold threshold to 200_000

Remove rb_yjit_call_threshold()

Remove conflict markers

Fix compilation errors

Threshold 1 should compile immediately

Debug deadlock issue with test_ractor

Fix call threshold issue with tests
k0kubun pushed a commit that referenced this pull request Oct 5, 2023
* YJIT: Add counter to measure how often we compile "cold" ISEQs (#535)

Fix counter name in DEFAULT_COUNTERS

YJIT: add --yjit-cold-threshold, don't compile cold ISEQs

YJIT: increase default cold threshold to 200_000

Remove rb_yjit_call_threshold()

Remove conflict markers

Fix compilation errors

Threshold 1 should compile immediately

Debug deadlock issue with test_ractor

Fix call threshold issue with tests

* Revert exception threshold logic. Document option in yjid.md

* (void) for 0 parameter functions in C99

* Rename iseq_entry_cold => cold_iseq_entry

* Document --yjit-cold-threshold in ruby.c

* Update doc/yjit/yjit.md

Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>

* Shorten help string to appease test

* Address bug found by Kokubun. Reorder logic.

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
k0kubun pushed a commit that referenced this pull request Oct 5, 2023
* YJIT: Add counter to measure how often we compile "cold" ISEQs (#535)

Fix counter name in DEFAULT_COUNTERS

YJIT: add --yjit-cold-threshold, don't compile cold ISEQs

YJIT: increase default cold threshold to 200_000

Remove rb_yjit_call_threshold()

Remove conflict markers

Fix compilation errors

Threshold 1 should compile immediately

Debug deadlock issue with test_ractor

Fix call threshold issue with tests

* Revert exception threshold logic. Document option in yjid.md

* (void) for 0 parameter functions in C99

* Rename iseq_entry_cold => cold_iseq_entry

* Document --yjit-cold-threshold in ruby.c

* Update doc/yjit/yjit.md

Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>

* Shorten help string to appease test

* Address bug found by Kokubun. Reorder logic.

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
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.

2 participants