File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,25 +131,27 @@ def load_fiddle
131131RUSAGE_INFO_V0 = 0
132132RI_RESIDENT_SIZE_OFFSET = 16 + 6 * 8
133133
134- # Memoized on a module, not on main: the Ractor harness freezes main.
134+ # On macOS, `get_rss` reads the RSS through Fiddle via `load_fiddle`. We load it when the harness
135+ # loads, rather than on the first RSS sample after a benchmark iteration. That's also before the
136+ # benchmark calls `use_gemfile`, so `load_fiddle` can activate the fiddle gem directly. After
137+ # `Bundler.setup`, it has to force-activate the gem through Bundler, which loads Bundler code that
138+ # can invalidate JIT-compiled code and adversely impact benchmark runs.
139+ #
140+ # Stored on a module, not on main: the Ractor harness freezes main.
135141module ProcPidRusage
136- @resolved = false
137-
138- def self . fn
139- return @fn if @resolved
140-
141- @resolved = true
142- @fn = begin
142+ if is_macos
143+ begin
143144 load_fiddle
144- Fiddle ::Function . new (
145+ @fn = Fiddle ::Function . new (
145146 Fiddle . dlopen ( nil ) [ 'proc_pid_rusage' ] ,
146147 [ Fiddle ::TYPE_INT , Fiddle ::TYPE_INT , Fiddle ::TYPE_VOIDP ] ,
147148 Fiddle ::TYPE_INT ,
148149 )
149150 rescue LoadError , Fiddle ::DLError , NameError
150- nil
151151 end
152152 end
153+
154+ def self . fn = @fn
153155end
154156
155157# The current RSS in bytes on macOS, read from libproc. Unlike ps this does not
You can’t perform that action at this time.
0 commit comments