Skip to content

Commit

Permalink
chore: Replace positive? with 'greater than 0' (#1586)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Kayla Reopelle (she/her) <[email protected]>
Co-authored-by: Robert <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent 3fde77b commit 540b77e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sdk/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ Style/ExplicitBlockArgument:
Enabled: false
Style/ModuleFunction:
Enabled: false
Style/NumericPredicate:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 540b77e

Please sign in to comment.