-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small perf improvement #1533
Small perf improvement #1533
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change in behaviour. Hash#drop(n)
removes the first n
elements, leaving the remainder. Hash#first(m)
retains the first m
elements, and drops the remainder. I.e. if MAX_MEMBER_COUNT
is 2 and hash
is {"a" => 1, "b" => 2, "c" => 3}
then the original code will set @hash = {"b" => 2, "c" => 3}
whereas your new code will set @hash = {"a" => 1, "b" => 2}
.
irb(main):001> hash = {"a" => 1, "b" => 2, "c" => 3}
=> {"a"=>1, "b"=>2, "c"=>3}
irb(main):002> Hash[hash.drop(1)]
=> {"b"=>2, "c"=>3}
irb(main):003> Hash[hash.first(2)]
=> {"a"=>1, "b"=>2}
🤦🏻♂️I’ll add a test for that so the next person can blindly trust
ChatGPT.
…On Fri, Oct 27, 2023 at 4:26 PM Francis Bogsanyi ***@***.***> wrote:
***@***.**** requested changes on this pull request.
This is a change in behaviour. Hash#drop(n) *removes* the first n
elements, leaving the remainder. Hash#first(m) *retains* the first m
elements, and drops the remainder. I.e. if MAX_MEMBER_COUNT is 2 and hash
is {"a" => 1, "b" => 2, "c" => 3} then the original code will set @hash =
{"b" => 2, "c" => 3} whereas your new code will set @hash = {"a" => 1,
"b" => 2}.
irb(main):001> hash = {"a" => 1, "b" => 2, "c" => 3}
=> {"a"=>1, "b"=>2, "c"=>3}
irb(main):002> Hash[hash.drop(1)]
=> {"b"=>2, "c"=>3}
irb(main):003> Hash[hash.first(2)]
=> {"a"=>1, "b"=>2}
—
Reply to this email directly, view it on GitHub
<#1533 (review)>,
or unsubscribe
<https:/notifications/unsubscribe-auth/AAFQUOR3D2D4OM2C2U754XDYBQKG5AVCNFSM6AAAAAA6TJ2B2KVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTOMBSGQ4TEOBZHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Thanks for highlighting this, though. I misread what this was fixing, and went off to check the spec for opentelemetry-ruby/sdk/lib/opentelemetry/sdk/trace/span.rb Lines 347 to 354 in afc7bc5
Fixing that will also change behaviour, but is required for spec compliance. I'll have to re-read the spec for tracestate propagation to see what's required there. I would prefer to avoid changing behaviour if the spec is ... not specific. |
Followup: the W3C
So the code in this PR is more correct, but not yet most correct. |
I saw this method in a few profiles and used ChatGPT to make it faster. Seems worth the effort.