-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Make Monitor a core class #15538
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
base: master
Are you sure you want to change the base?
Make Monitor a core class #15538
Conversation
This comment has been minimized.
This comment has been minimized.
f5013f6 to
634545f
Compare
|
You might want to move |
|
@nobu I did, no? |
|
|
|
Oh woops. |
ad78b6e to
32815a1
Compare
[Feature #21788] It allows monitor to access internal routines and remove some overhead. Before: ``` ruby 4.0.0dev (2025-12-13T04:52:13Z master 71dd272) +YJIT +PRISM [arm64-darwin25] Warming up -------------------------------------- Mutex 2.111M i/100ms Monitor 1.736M i/100ms Calculating ------------------------------------- Mutex 25.050M (± 0.4%) i/s (39.92 ns/i) - 126.631M in 5.055208s Monitor 19.809M (± 0.1%) i/s (50.48 ns/i) - 100.672M in 5.082015s ``` After: ``` ruby 4.0.0dev (2025-12-13T06:49:18Z core-monitor 6fabf38) +YJIT +PRISM [arm64-darwin25] Warming up -------------------------------------- Mutex 2.144M i/100ms Monitor 1.859M i/100ms Calculating ------------------------------------- Mutex 24.771M (± 0.4%) i/s (40.37 ns/i) - 124.342M in 5.019716s Monitor 23.722M (± 0.4%) i/s (42.15 ns/i) - 118.998M in 5.016361s ``` Bench: ```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 ```
|
|
||
| # Ignore CRuby internals | ||
| features -= %w[encdb transdb windows_1252 windows_31j] | ||
| features -= %w[encdb transdb windows_1252 windows_31 monitor] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
monitor is not CRuby internal (it's a long-time stdlib/well known feature name), so let's add it under a ruby_version_is "4.1" do guard like pathname below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e. the point is that other Ruby implementations should also to rb_provide() or equivalent so require "monitor" keeps working.
| # | ||
| # Copyright (C) 2001 Shugo Maeda <shugo@ruby-lang.org> | ||
| # | ||
| # This library is distributed under the terms of the Ruby license. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move this whole file in thread_sync.rb or /monitor.rb?
| # # exclusive access | ||
| # end | ||
| # | ||
| class Monitor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this file should define any method on Monitor if Monitor is core.
[Feature #21788]
It allows monitor to access internal routines and remove some overhead.
Before:
After:
Bench: