You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I do not know if this deserves a cop or if it is the correct place to discuss this kind of requests
While performing some tests, I've noticed that starting from Ruby 2.7 (because of keyword arguments?), {}.merge({ hello: 'world', foo: 'bar' }) is about 15% faster than {}.merge(hello: 'world', foo: 'bar') and uses the same memory.
I may tend to omit curl parenthesis when adding multiple keys in situations like
# I tend to writehash.merge(key1: value1,key2: value2,key3: value3)# Rather thanhash.merge({key1: value1,key2: value2,key3: value3})
Slowness is directly related to the number of arguments passed
M1 Pro, x86 Ruby, slowness of merge(kv1) compared to merge({ kv1 })
Ruby
1 arg
2 args
3 args
4 args
2.6.10
same-ish
same-ish
same-ish
same-ish
2.7.8
1.07x
1.16x
1.23x
1.32x
3.2.2
1.09x
1.16x
1.25x
1.29x
3.3.0-p2
1.07x
1.14x
1.20x
1.25x
The lower, the better
Describe the solution you'd like
Maybe introduce a Cop to check that merge is not called with multiple keys
Describe alternatives you've considered
Not having this Cop is just fine
Additional context
A similar performance drop happens with merge!. Performance/RedundantMerge allows to detect issues when there are one or two arguments, but with three arguments RuboCop does not complain
Hi,
I do not know if this deserves a cop or if it is the correct place to discuss this kind of requests
While performing some tests, I've noticed that starting from Ruby 2.7 (because of keyword arguments?),
{}.merge({ hello: 'world', foo: 'bar' })
is about 15% faster than{}.merge(hello: 'world', foo: 'bar')
and uses the same memory.I may tend to omit curl parenthesis when adding multiple keys in situations like
Slowness is directly related to the number of arguments passed
M1 Pro, x86 Ruby, slowness of
merge(kv1)
compared tomerge({ kv1 })
The lower, the better
Describe the solution you'd like
Maybe introduce a Cop to check that merge is not called with multiple keys
Describe alternatives you've considered
Not having this Cop is just fine
Additional context
A similar performance drop happens with
merge!
.Performance/RedundantMerge
allows to detect issues when there are one or two arguments, but with three arguments RuboCop does not complainExample:
The text was updated successfully, but these errors were encountered: