diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2025-12-03 14:50:35 +0100 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2025-12-03 17:54:27 +0100 |
| commit | fcf3939780972d587b18afc26c4abd2da2c0b7ec (patch) | |
| tree | 501ae2cb5aba924ae988659e0cb0f506d7d92629 /include/ruby/missing.h | |
| parent | d7dffcdbeeee81bb3bbe63b86620cb682eb3ab23 (diff) | |
Speedup TypedData_Get_Struct
While profiling `Monitor#synchronize` and `Mutex#synchronize`
I noticed a fairly significant amount of time spent in
`rb_check_typeddata`.
By implementing a fast path that assumes the object is valid
and that can be inlined, it does make a significant difference:
Before:
```
Mutex 13.548M (± 3.6%) i/s (73.81 ns/i) - 68.566M in 5.067444
Monitor 10.497M (± 6.5%) i/s (95.27 ns/i) - 52.529M in 5.032698s
```
After:
```
Mutex 20.887M (± 0.3%) i/s (47.88 ns/i) - 106.021M in 5.075989s
Monitor 16.245M (±13.3%) i/s (61.56 ns/i) - 80.705M in 5.099680s
```
```ruby
require 'bundler/inline'
gemfile do
gem "benchmark-ips"
end
mutex = Mutex.new
require "monitor"
monitor = Monitor.new
Benchmark.ips do |x|
x.report("Mutex") { mutex.synchronize { } }
x.report("Monitor") { monitor.synchronize { } }
end
```
Diffstat (limited to 'include/ruby/missing.h')
0 files changed, 0 insertions, 0 deletions
