mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
That call is surprisingly expensive, so trying doing it once
in `#synchronize` and then passing the EC to lock and unlock
saves quite a few cycles.
Before:
```
ruby 4.0.0dev (2025-12-10T09:30:18Z master c5608ab4d7) +YJIT +PRISM [arm64-darwin25]
Warming up --------------------------------------
Mutex 1.888M i/100ms
Monitor 1.633M i/100ms
Calculating -------------------------------------
Mutex 22.610M (± 0.2%) i/s (44.23 ns/i) - 113.258M in 5.009097s
Monitor 19.148M (± 0.3%) i/s (52.22 ns/i) - 96.366M in 5.032755s
```
After:
```
ruby 4.0.0dev (2025-12-10T10:40:07Z speedup-mutex 1c901cd4f8) +YJIT +PRISM [arm64-darwin25]
Warming up --------------------------------------
Mutex 2.095M i/100ms
Monitor 1.578M i/100ms
Calculating -------------------------------------
Mutex 24.456M (± 0.4%) i/s (40.89 ns/i) - 123.584M in 5.053418s
Monitor 19.176M (± 0.1%) i/s (52.15 ns/i) - 96.243M in 5.018977s
```
Bench:
```
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
```
44 lines
1.6 KiB
C
44 lines
1.6 KiB
C
#ifndef INTERNAL_EVAL_H /*-*-C-*-vi:se ft=c:*/
|
|
#define INTERNAL_EVAL_H
|
|
/**
|
|
* @author Ruby developers <ruby-core@ruby-lang.org>
|
|
* @copyright This file is a part of the programming language Ruby.
|
|
* Permission is hereby granted, to either redistribute and/or
|
|
* modify this file, provided that the conditions mentioned in the
|
|
* file COPYING are met. Consult the file for details.
|
|
* @brief Internal header for the evaluator.
|
|
* @note There also is eval_intern.h, which is evaluator's internal
|
|
* header (related to this file, but not the same role).
|
|
*/
|
|
#include "ruby/ruby.h" /* for ID */
|
|
#include "vm_core.h" /* for ID */
|
|
|
|
#define id_signo ruby_static_id_signo
|
|
#define id_status ruby_static_id_status
|
|
|
|
/* eval.c */
|
|
struct rb_refinements_data {
|
|
VALUE refinement;
|
|
VALUE refinements;
|
|
};
|
|
|
|
extern ID ruby_static_id_signo;
|
|
extern ID ruby_static_id_status;
|
|
VALUE rb_refinement_module_get_refined_class(VALUE module);
|
|
void rb_class_modify_check(VALUE);
|
|
NORETURN(VALUE rb_f_raise(int argc, VALUE *argv));
|
|
VALUE rb_exception_setup(int argc, VALUE *argv);
|
|
void rb_refinement_setup(struct rb_refinements_data *data, VALUE module, VALUE klass);
|
|
void rb_vm_using_module(VALUE module);
|
|
VALUE rb_top_main_class(const char *method);
|
|
VALUE rb_ec_ensure(rb_execution_context_t *ec, VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2);
|
|
|
|
/* eval_error.c */
|
|
VALUE rb_get_backtrace(VALUE info);
|
|
|
|
/* eval_jump.c */
|
|
void rb_call_end_proc(VALUE data);
|
|
void rb_mark_end_proc(void);
|
|
|
|
#endif /* INTERNAL_EVAL_H */
|