Skip to content

Commit

Permalink
Implement optimize send in yjit (#6488)
Browse files Browse the repository at this point in the history
* Implement optimize send in yjit

This successfully makes all our benchmarks exit way less for optimize send reasons.
It makes some benchmarks faster, but not by as much as I'd like. I think this implementation
works, but there are definitely more optimial arrangements. For example, what if we compiled
send to a jump table? That seems like perhaps the most optimal we could do, but not obvious (to me)
how to implement give our current setup.

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>

* Attempt at fixing the issues raised by @XrXr

* fix allowlist

* returns 0 instead of nil when not found

* remove comment about encoding exception

* Fix up c changes

* Update assert

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>

* get rid of unneeded code and fix the flags

* Apply suggestions from code review

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>

* rename and fix typo

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
  • Loading branch information
jimmyhmiller and XrXr committed Oct 11, 2022
1 parent 913979b commit 467992e
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 17 deletions.
22 changes: 22 additions & 0 deletions symbol.c
Expand Up @@ -1112,6 +1112,28 @@ rb_check_id(volatile VALUE *namep)
return lookup_str_id(name);
}

// Used by yjit for handling .send without throwing exceptions
ID
rb_get_symbol_id(VALUE name)
{
if (STATIC_SYM_P(name)) {
return STATIC_SYM2ID(name);
}
else if (DYNAMIC_SYM_P(name)) {
if (SYMBOL_PINNED_P(name)) {
return RSYMBOL(name)->id;
}
else {
return 0;
}
}
else {
RUBY_ASSERT_ALWAYS(RB_TYPE_P(name, T_STRING));
return lookup_str_id(name);
}
}


VALUE
rb_check_symbol(volatile VALUE *namep)
{
Expand Down
2 changes: 2 additions & 0 deletions yjit.c
Expand Up @@ -509,6 +509,8 @@ rb_get_cme_def_body_attr_id(const rb_callable_method_entry_t *cme)
return cme->def->body.attr.id;
}

ID rb_get_symbol_id(VALUE namep);

enum method_optimized_type
rb_get_cme_def_body_optimized_type(const rb_callable_method_entry_t *cme)
{
Expand Down
1 change: 1 addition & 0 deletions yjit/bindgen/src/main.rs
Expand Up @@ -332,6 +332,7 @@ fn main() {
.allowlist_function("rb_get_cfp_ep_level")
.allowlist_function("rb_get_cme_def_type")
.allowlist_function("rb_get_cme_def_body_attr_id")
.allowlist_function("rb_get_symbol_id")
.allowlist_function("rb_get_cme_def_body_optimized_type")
.allowlist_function("rb_get_cme_def_body_optimized_index")
.allowlist_function("rb_get_cme_def_body_cfunc")
Expand Down

0 comments on commit 467992e

Please sign in to comment.