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: Improve performance #4743

Merged
merged 26 commits into from
Dec 14, 2023

Conversation

cdvr1993
Copy link
Contributor

@cdvr1993 cdvr1993 commented Dec 5, 2023

Several of our microservices during profiling report a considerable cost coming from the regex that validate the key and the value (in the range of 3-6%). For instance:

Screenshot 2023-12-04 at 4 32 35 PM

After checking the regex I saw that we can easily replace that to a simple for loop implementation. All tests are passing, but hopefully didn't miss a condition.

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/baggage
cpu: AMD EPYC 7B13
             │ /tmp/old.txt │            /tmp/new.txt             │
             │    sec/op    │   sec/op     vs base                │
New-96          1.394µ ± 5%   1.382µ ± 7%        ~ (p=0.190 n=10)
NewMember-96   307.10n ± 1%   39.66n ± 1%  -87.08% (p=0.000 n=10)
Parse-96        4.575µ ± 6%   1.037µ ± 7%  -77.33% (p=0.000 n=10)
geomean         1.251µ        384.5n       -69.26%

             │ /tmp/old.txt  │             /tmp/new.txt             │
             │     B/op      │    B/op     vs base                  │
New-96          835.0 ± 0%     835.0 ± 0%        ~ (p=1.000 n=10) ¹
NewMember-96    0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
Parse-96       1108.0 ± 0%     832.0 ± 0%  -24.91% (p=0.000 n=10)
geomean                    ²                -9.11%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

             │ /tmp/old.txt  │             /tmp/new.txt             │
             │   allocs/op   │ allocs/op   vs base                  │
New-96          16.00 ± 0%     16.00 ± 0%        ~ (p=1.000 n=10) ¹
NewMember-96    0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
Parse-96       11.000 ± 0%     7.000 ± 0%  -36.36% (p=0.000 n=10)
geomean                    ²               -13.99%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/baggage
cpu: AMD EPYC 7B13
             │ /tmp/old.txt  │            /tmp/new.txt             │
             │    sec/op     │   sec/op     vs base                │
NewMember-96   368.20n ± 21%   46.94n ± 3%  -87.25% (p=0.000 n=10)
Copy link

linux-foundation-easycla bot commented Dec 5, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@cdvr1993 cdvr1993 changed the title [WIP] Improve NewMember performance by ~9x Improve NewMember performance by ~9x Dec 5, 2023
Copy link

codecov bot commented Dec 5, 2023

Codecov Report

Merging #4743 (412bf43) into main (0c1c434) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #4743   +/-   ##
=====================================
  Coverage   82.0%   82.1%           
=====================================
  Files        225     225           
  Lines      18242   18325   +83     
=====================================
+ Hits       14976   15059   +83     
  Misses      2981    2981           
  Partials     285     285           
Files Coverage Δ
baggage/baggage.go 99.2% <100.0%> (+0.2%) ⬆️

baggage/baggage.go Outdated Show resolved Hide resolved
@pellared
Copy link
Member

pellared commented Dec 5, 2023

Please fix the build (lint) failures.

@pellared
Copy link
Member

pellared commented Dec 6, 2023

Can you please run all benchmarks for the whole package? The changes should also affect BenchmarkNew and BenchmarkParse.

baggage/baggage.go Outdated Show resolved Hide resolved
Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Thank you the contribution.

I agree with @pellared's comments in that this looks like a partial solution. There is coupling with other functionality that this does not address. I do not think these changes should be accepted as they currently are presented.

baggage/baggage.go Outdated Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
@cdvr1993 cdvr1993 changed the title Improve NewMember performance by ~9x Improve NewMember & Parse performance by >3x Dec 6, 2023
baggage/baggage.go Outdated Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

I did my best in reviewing the PR. I made some IMO trivial (editorial) changes directly. I also have a bigger suggestion on how parsePropertyInternal could be implemented to make it more readable and maintainable.

baggage/baggage_test.go Show resolved Hide resolved
baggage/baggage_test.go Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
baggage/baggage_test.go Outdated Show resolved Hide resolved
baggage/baggage_test.go Outdated Show resolved Hide resolved
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Approving.

However, I would appreciate adding some more comments to the code as suggested in #4743 (comment) and #4743 (comment).

Thank you for your contribution 👍

@pellared pellared changed the title Improve NewMember & Parse performance by >3x baggage: Improve performance Dec 11, 2023
baggage/baggage.go Show resolved Hide resolved
baggage/baggage.go Outdated Show resolved Hide resolved
@pellared pellared added this to the v1.23.0 milestone Dec 12, 2023
@cdvr1993
Copy link
Contributor Author

hi everyone, just checking in, is there anything else missing to merge this? Also, I couldn't find it, what is the process for releasing? Do you release on a schedule or is it on-demand?

@pellared pellared merged commit 057f897 into open-telemetry:main Dec 14, 2023
25 checks passed
@MrAlias MrAlias modified the milestones: v1.23.0, v1.22.0 Jan 11, 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.

4 participants