mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
proc.c: Make Method and UnboundMethod embded
Avoid some needless malloc churn
```
compare-ruby: ruby 3.3.0dev (2023-11-20T02:02:55Z master 701b0650de
) [arm64-darwin22]
last_commit=[ruby/prism] feat: add encoding for IBM865 (https://github.com/ruby/prism/pull/1884)
built-ruby: ruby 3.3.0dev (2023-11-20T16:23:07Z embedded-methods e35284bfaa) [arm64-darwin22]
warming up..
| |compare-ruby|built-ruby|
|:------------------------|-----------:|---------:|
|allocate_method | 8.413M| 12.333M|
| | -| 1.47x|
|allocate_unbound_method | 8.083M| 11.607M|
| | -| 1.44x|
```
```
prelude: |
class SomeClass
def foo
end
end
some_object = SomeClass.new
benchmark:
allocate_method: some_object.method(:foo)
allocate_unbound_method: SomeClass.instance_method(:foo)
```
This commit is contained in:
parent
5278742bf0
commit
ffb1eb37e7
1 changed files with 5 additions and 5 deletions
10
proc.c
10
proc.c
|
@ -1600,7 +1600,7 @@ bm_mark_and_move(void *ptr)
|
||||||
static size_t
|
static size_t
|
||||||
bm_memsize(const void *ptr)
|
bm_memsize(const void *ptr)
|
||||||
{
|
{
|
||||||
return sizeof(struct METHOD);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const rb_data_type_t method_data_type = {
|
static const rb_data_type_t method_data_type = {
|
||||||
|
@ -1611,7 +1611,7 @@ static const rb_data_type_t method_data_type = {
|
||||||
bm_memsize,
|
bm_memsize,
|
||||||
bm_mark_and_move,
|
bm_mark_and_move,
|
||||||
},
|
},
|
||||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
|
||||||
};
|
};
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
@ -1805,8 +1805,8 @@ method_eq(VALUE method, VALUE other)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
|
|
||||||
Check_TypedStruct(method, &method_data_type);
|
Check_TypedStruct(method, &method_data_type);
|
||||||
m1 = (struct METHOD *)DATA_PTR(method);
|
m1 = (struct METHOD *)RTYPEDDATA_GET_DATA(method);
|
||||||
m2 = (struct METHOD *)DATA_PTR(other);
|
m2 = (struct METHOD *)RTYPEDDATA_GET_DATA(other);
|
||||||
|
|
||||||
klass1 = method_entry_defined_class(m1->me);
|
klass1 = method_entry_defined_class(m1->me);
|
||||||
klass2 = method_entry_defined_class(m2->me);
|
klass2 = method_entry_defined_class(m2->me);
|
||||||
|
@ -2222,7 +2222,7 @@ rb_mod_define_method_with_visibility(int argc, VALUE *argv, VALUE mod, const str
|
||||||
if (!id) id = rb_to_id(name);
|
if (!id) id = rb_to_id(name);
|
||||||
|
|
||||||
if (is_method) {
|
if (is_method) {
|
||||||
struct METHOD *method = (struct METHOD *)DATA_PTR(body);
|
struct METHOD *method = (struct METHOD *)RTYPEDDATA_GET_DATA(body);
|
||||||
if (method->me->owner != mod && !RB_TYPE_P(method->me->owner, T_MODULE) &&
|
if (method->me->owner != mod && !RB_TYPE_P(method->me->owner, T_MODULE) &&
|
||||||
!RTEST(rb_class_inherited_p(mod, method->me->owner))) {
|
!RTEST(rb_class_inherited_p(mod, method->me->owner))) {
|
||||||
if (FL_TEST(method->me->owner, FL_SINGLETON)) {
|
if (FL_TEST(method->me->owner, FL_SINGLETON)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue