From db2dea26fe8c5d22660b2269f8485fe4912ad94f Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 10 Jan 2024 04:49:40 +0000 Subject: [PATCH] Add Ruby-3.3 Process.warmup --- Changelog.md | 11 ++++--- lib/mutant/mutation/runner.rb | 2 ++ lib/mutant/world.rb | 4 +++ spec/unit/mutant/mutation/runner_spec.rb | 14 ++++++++- spec/unit/mutant/world_spec.rb | 39 ++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index bac14f8ed..9499a5fff 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,12 +1,15 @@ # v0.11.28 -* Fix CLI parsing issue where arguments given to `mutant environment` where silently ignored. - [#1416](https://github.com/mbj/mutant/pull/1416) +* [#1416](https://github.com/mbj/mutant/pull/1416) + Fix CLI parsing issue where arguments given to `mutant environment` where silently ignored. -* Change to report efficiency instead of overhead. +* [#1415](https://github.com/mbj/mutant/pull/1415) + Change to report efficiency instead of overhead. Efficiency is defined by `killtime / runtime`. - [#1415](https://github.com/mbj/mutant/pull/1415) +* [#1413](https://github.com/mbj/mutant/pull/1413) + + Add `Process.warmup` optimization for ruby-3.3+ which yields a noticable speed improvement. # v0.11.27 2023-12-01 diff --git a/lib/mutant/mutation/runner.rb b/lib/mutant/mutation/runner.rb index 701274f22..032615798 100644 --- a/lib/mutant/mutation/runner.rb +++ b/lib/mutant/mutation/runner.rb @@ -15,6 +15,8 @@ def self.call(env) def self.run_mutation_analysis(env) reporter = reporter(env) + env.world.process_warmup + env .record(:analysis) { run_driver(reporter, async_driver(env)) } .tap { |result| env.record(:report) { reporter.report(result) } } diff --git a/lib/mutant/world.rb b/lib/mutant/world.rb index 2677735eb..398b9623a 100644 --- a/lib/mutant/world.rb +++ b/lib/mutant/world.rb @@ -82,5 +82,9 @@ def deadline(allowed_time) def record(name, &block) recorder.record(name, &block) end + + def process_warmup + process.warmup if process.respond_to?(:warmup) + end end # World end # Mutant diff --git a/spec/unit/mutant/mutation/runner_spec.rb b/spec/unit/mutant/mutation/runner_spec.rb index 9b1a0c480..b15da1aed 100644 --- a/spec/unit/mutant/mutation/runner_spec.rb +++ b/spec/unit/mutant/mutation/runner_spec.rb @@ -8,7 +8,8 @@ let(:emit_mutation_worker_process_start) { instance_double(Proc) } let(:env_result) { instance_double(Mutant::Result::Env) } let(:reporter) { instance_double(Mutant::Reporter, delay: delay) } - let(:world) { fake_world } + let(:world) { instance_double(Mutant::World) } + let(:timer) { instance_double(Mutant::Timer) } let(:env) do instance_double( @@ -55,6 +56,7 @@ end before do + allow(world).to receive_messages(timer: timer) allow(world.timer).to receive_messages(now: 1.0) end @@ -70,6 +72,11 @@ def apply selector: :start, arguments: [env] }, + { + receiver: world, + selector: :process_warmup, + arguments: [] + }, { receiver: env, selector: :record, @@ -147,6 +154,11 @@ def apply selector: :start, arguments: [env] }, + { + receiver: world, + selector: :process_warmup, + arguments: [], + }, { receiver: env, selector: :record, diff --git a/spec/unit/mutant/world_spec.rb b/spec/unit/mutant/world_spec.rb index a3c308c8b..65eaaec1a 100644 --- a/spec/unit/mutant/world_spec.rb +++ b/spec/unit/mutant/world_spec.rb @@ -140,4 +140,43 @@ def apply end end end + + describe '#process_warmup' do + let(:process) { double(Process) } + + subject { super().with(process: process) } + + def apply + subject.process_warmup + end + + before do + allow(process).to receive_messages( + respond_to?: respond_to?, + warmup: process + ) + end + + context 'when process supports warmup' do + let(:respond_to?) { true } + + it 'performs warmup' do + apply + + expect(process).to have_received(:respond_to?).with(:warmup).ordered + expect(process).to have_received(:warmup).ordered + end + end + + context 'when process supports warmup' do + let(:respond_to?) { false } + + it 'performs warmup' do + apply + + expect(process).to have_received(:respond_to?).with(:warmup) + expect(process).to_not have_received(:warmup) + end + end + end end