From 1166d1eb73e3374eacf221b9ac60435d00480538 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Tue, 30 Jan 2024 20:52:00 +0100 Subject: [PATCH] chore: Replace positive? with 'greater than 0' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Opentelemtry used in many projects and micro performance could impact a lot. The default rubocop style was not designed in performance overview. [subjective] Benchmarks shows the `Numeric#positive?` is 1.32x slower, than 'number > 0'. ``` ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23] Warming up -------------------------------------- compare with 0 1.000 i/100ms positive? 1.000 i/100ms Calculating ------------------------------------- compare with 0 3.153 (± 0.0%) i/s - 95.000 in 30.132600s positive? 2.397 (± 0.0%) i/s - 72.000 in 30.042688s Comparison: compare with 0: 3.2 i/s positive?: 2.4 i/s - 1.32x slower ``` The change disables Style/NumericPredicate for rubocop as well. Signed-off-by: Michael Nikitochkin --- sdk/.rubocop.yml | 2 ++ sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/.rubocop.yml b/sdk/.rubocop.yml index 8db4c7b203..26e0209d27 100644 --- a/sdk/.rubocop.yml +++ b/sdk/.rubocop.yml @@ -20,3 +20,5 @@ Style/ExplicitBlockArgument: Enabled: false Style/ModuleFunction: Enabled: false +Style/NumericPredicate: + Enabled: false diff --git a/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb b/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb index 5e11b51356..18df3cc6b5 100644 --- a/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb @@ -80,7 +80,7 @@ def on_finish(span) lock do reset_on_fork n = spans.size + 1 - max_queue_size - if n.positive? + if n > 0 dropped_spans = spans.shift(n) report_dropped_spans(dropped_spans, reason: 'buffer-full', function: __method__.to_s) end