Skip to content
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

baggage: more efficient member validation #5214

Merged
merged 8 commits into from Apr 19, 2024

Conversation

kevinburkesegment
Copy link
Contributor

@kevinburkesegment kevinburkesegment commented Apr 16, 2024

Instead of performing many, many comparisons for each character in a key and value, create an array of 128 bits and test for membership in that array, which is quicker.

Benchmarks on a Mac M1, ran 20 times.

name                             old time/op    new time/op    delta
New-8                               747ns ± 4%     741ns ± 3%    ~     (p=0.089 n=17+19)
NewMemberRaw-8                     11.4ns ± 1%    10.9ns ± 1%  -4.67%  (p=0.000 n=17+19)
Parse-8                             619ns ± 2%     603ns ± 1%  -2.54%  (p=0.000 n=18+18)
String-8                           1.12µs ± 4%    1.09µs ± 2%  -2.65%  (p=0.000 n=19+18)
ValueEscape/nothing_to_escape-8    6.93ns ± 1%    6.94ns ± 0%  +0.18%  (p=0.012 n=18+20)
ValueEscape/requires_escaping-8    26.3ns ± 2%    26.1ns ± 1%  -0.91%  (p=0.000 n=19+19)
ValueEscape/long_value-8            641ns ± 4%     595ns ± 1%  -7.14%  (p=0.000 n=18+17)

The approach is taken from the same approach in encoding/json in the standard library, which I also contributed.

Copy link

codecov bot commented Apr 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.5%. Comparing base (ed666f7) to head (2498094).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #5214     +/-   ##
=======================================
- Coverage   84.5%   84.5%   -0.1%     
=======================================
  Files        258     258             
  Lines      17110   17096     -14     
=======================================
- Hits       14468   14452     -16     
- Misses      2343    2345      +2     
  Partials     299     299             
Files Coverage Δ
baggage/baggage.go 98.1% <100.0%> (-0.1%) ⬇️

... and 1 file with indirect coverage changes

@kevinburkesegment
Copy link
Contributor Author

I don't think this PR needs a changelog entry.

@XSAM XSAM added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Apr 16, 2024
Copy link
Member

@XSAM XSAM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with this

@pellared
Copy link
Member

I don't think this PR needs a changelog entry.

We tend to add changelog entries when we improve performance.

@pellared pellared removed the Skip Changelog PRs that do not require a CHANGELOG.md entry label Apr 16, 2024
@pellared
Copy link
Member

pellared commented Apr 16, 2024

The approach is taken from the same approach in encoding/json in the standard library, which I also contributed.

Can you please provide a reference? I cannot find anything here: https://github.com/golang/go/pulls/kevinburkesegment

@kevinburkesegment
Copy link
Contributor Author

Can you please provide a reference? I cannot find anything here: https://github.com/golang/go/pulls/kevinburkesegment

Ah, this is my work account - all of my Go contributions are on the email under my other Github username, kevinburke, but also Google does not use Github for pull requests.

That commit is here: golang/go@ed8f207

Instead of performing many, many comparisons for each character in
a key and value, create an array of 128 bits and test for membership
in that array, which is quicker.

Benchmarks on a Mac M1, ran 20 times.

```
name                             old time/op    new time/op    delta
New-8                               747ns ± 4%     741ns ± 3%    ~     (p=0.089 n=17+19)
NewMemberRaw-8                     11.4ns ± 1%    10.9ns ± 1%  -4.67%  (p=0.000 n=17+19)
Parse-8                             619ns ± 2%     603ns ± 1%  -2.54%  (p=0.000 n=18+18)
String-8                           1.12µs ± 4%    1.09µs ± 2%  -2.65%  (p=0.000 n=19+18)
ValueEscape/nothing_to_escape-8    6.93ns ± 1%    6.94ns ± 0%  +0.18%  (p=0.012 n=18+20)
ValueEscape/requires_escaping-8    26.3ns ± 2%    26.1ns ± 1%  -0.91%  (p=0.000 n=19+19)
ValueEscape/long_value-8            641ns ± 4%     595ns ± 1%  -7.14%  (p=0.000 n=18+17)
```
baggage/baggage.go Outdated Show resolved Hide resolved
@pellared
Copy link
Member

@open-telemetry/go-approvers waiting 1 day before merging.

@pellared pellared changed the title baggage: more efficient Parse implementation baggage: more efficient member validation Apr 19, 2024
@pellared pellared merged commit 906c490 into open-telemetry:main Apr 19, 2024
26 checks passed
@MrAlias MrAlias added this to the v1.26.0 milestone Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants