diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-01-11 09:23:03 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-01-11 11:06:58 -0500 |
commit | abff5f62037284024aaf469fc46a6e8de98fa1e3 (patch) | |
tree | 47347d74b361020233615449e9c508b82afaccdc /spec/ruby | |
parent | d86833e717104b477c32e135a15fcbf380c6abb2 (diff) |
Move classpath to rb_classext_t
This commit moves the classpath (and tmp_classpath) from instance
variables to the rb_classext_t. This improves performance as we no
longer need to set an instance variable when assigning a classpath to
a class.
I benchmarked with the following script:
```ruby
name = :MyClass
puts(Benchmark.measure do
10_000_000.times do |i|
Object.const_set(name, Class.new)
Object.send(:remove_const, name)
end
end)
```
Before this patch:
```
5.440119 0.025264 5.465383 ( 5.467105)
```
After this patch:
```
4.889646 0.028325 4.917971 ( 4.942678)
```
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7096
Diffstat (limited to 'spec/ruby')
-rw-r--r-- | spec/ruby/optional/capi/object_spec.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb index 25a43d8908..9efc892202 100644 --- a/spec/ruby/optional/capi/object_spec.rb +++ b/spec/ruby/optional/capi/object_spec.rb @@ -993,13 +993,19 @@ describe "CApiObject" do end it "calls the callback function for each cvar and ivar on a class" do + exp = [:@@cvar, :foo, :@@cvar2, :bar, :@ivar, :baz] + exp.unshift(:__classpath__, 'CApiObjectSpecs::CVars') if RUBY_VERSION < "3.3" + ary = @o.rb_ivar_foreach(CApiObjectSpecs::CVars) - ary.should == [:__classpath__, 'CApiObjectSpecs::CVars', :@@cvar, :foo, :@@cvar2, :bar, :@ivar, :baz] + ary.should == exp end it "calls the callback function for each cvar and ivar on a module" do + exp = [:@@mvar, :foo, :@@mvar2, :bar, :@ivar, :baz] + exp.unshift(:__classpath__, 'CApiObjectSpecs::MVars') if RUBY_VERSION < "3.3" + ary = @o.rb_ivar_foreach(CApiObjectSpecs::MVars) - ary.should == [:__classpath__, 'CApiObjectSpecs::MVars', :@@mvar, :foo, :@@mvar2, :bar, :@ivar, :baz] + ary.should == exp end end |