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: Member.String encodes only when necessary #4775

Merged
merged 10 commits into from
Dec 28, 2023

Conversation

pellared
Copy link
Member

@pellared pellared commented Dec 21, 2023

Fixes #4773

I also added Add UTF-8 test cases and some benchmarks.

Benchmark:

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/baggage
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
BenchmarkNew-16                   668466              1628 ns/op             832 B/op         16 allocs/op
BenchmarkNewMember-16           26077026                45.27 ns/op            0 B/op          0 allocs/op
BenchmarkParse-16                 954313              1116 ns/op             832 B/op          7 allocs/op
BenchmarkString-16                569619              1893 ns/op             960 B/op         18 allocs/op
BenchmarkValueEscape/nothing_to_escape-16               135047982                7.684 ns/op           0 B/op          0 allocs/op
BenchmarkValueEscape/requires_escaping-16               28184155                42.72 ns/op           16 B/op          1 allocs/op
BenchmarkValueEscape/long_value-16                       1492291               987.6 ns/op           576 B/op          2 allocs/op

Benchstat (in old.txt the benchmarks use url.PathEscape instead of valueEscape):

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/baggage
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
                                 │   old.txt    │               new.txt               │
                                 │    sec/op    │   sec/op     vs base                │
New-16                              1.221µ ± 5%   1.262µ ± 7%        ~ (p=0.055 n=10)
NewMember-16                        35.38n ± 5%   35.50n ± 3%        ~ (p=0.811 n=10)
Parse-16                            963.8n ± 4%   929.9n ± 3%   -3.52% (p=0.019 n=10)
String-16                           2.183µ ± 6%   1.632µ ± 4%  -25.22% (p=0.000 n=10)
ValueEscape/nothing_to_escape-16   13.465n ± 6%   6.957n ± 4%  -48.33% (p=0.000 n=10)
ValueEscape/requires_escaping-16    67.95n ± 5%   36.34n ± 6%  -46.52% (p=0.000 n=10)
ValueEscape/long_value-16          1596.0n ± 5%   739.2n ± 5%  -53.68% (p=0.000 n=10)
geomean                             279.3n        199.8n       -28.48%

                                 │    old.txt    │               new.txt                │
                                 │     B/op      │    B/op     vs base                  │
New-16                              832.0 ± 0%     832.0 ± 0%        ~ (p=1.000 n=10) ¹
NewMember-16                        0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
Parse-16                            832.0 ± 0%     832.0 ± 0%        ~ (p=1.000 n=10) ¹
String-16                          1024.0 ± 0%     960.0 ± 0%   -6.25% (p=0.000 n=10)
ValueEscape/nothing_to_escape-16    0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
ValueEscape/requires_escaping-16    16.00 ± 0%     16.00 ± 0%        ~ (p=1.000 n=10) ¹
ValueEscape/long_value-16           640.0 ± 0%     576.0 ± 0%  -10.00% (p=0.000 n=10)
geomean                                        ²                -2.40%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                 │   old.txt    │               new.txt               │
                                 │  allocs/op   │ allocs/op   vs base                 │
New-16                             16.00 ± 0%     16.00 ± 0%       ~ (p=1.000 n=10) ¹
NewMember-16                       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Parse-16                           7.000 ± 0%     7.000 ± 0%       ~ (p=1.000 n=10) ¹
String-16                          18.00 ± 0%     18.00 ± 0%       ~ (p=1.000 n=10) ¹
ValueEscape/nothing_to_escape-16   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
ValueEscape/requires_escaping-16   1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
ValueEscape/long_value-16          2.000 ± 0%     2.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                       ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

The results of String and ValueEscape show improvement.

Copy link

codecov bot commented Dec 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d23c060) 82.2% compared to head (005ba1b) 82.2%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #4775   +/-   ##
=====================================
  Coverage   82.2%   82.2%           
=====================================
  Files        226     226           
  Lines      18344   18383   +39     
=====================================
+ Hits       15087   15126   +39     
  Misses      2975    2975           
  Partials     282     282           
Files Coverage Δ
baggage/baggage.go 100.0% <100.0%> (ø)

@dmathieu
Copy link
Member

Should you run benchstat to compare the benchmarks between main and your branch?

@pellared
Copy link
Member Author

Should you run benchstat to compare the benchmarks between main and your branch?

I can do that today in a few hours or tomorrow morning.
The result should be similar (maybe a little faster as there should be a few CPU cycles less). I intentionally almost copied the code from url.PathEscape. I wanted to add the benchmarks if someone would want to improve it in future.

@pellared
Copy link
Member Author

@dmathieu Benchstat results added.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

I have no objection to this as an optimization of existing incorrect behavior - its not supposed to encode anything at all, only Propagator should be doing the encoding.

@pellared pellared merged commit 08b856f into open-telemetry:main Dec 28, 2023
25 checks passed
@MrAlias
Copy link
Contributor

MrAlias commented Jan 2, 2024

This was merged without two approvals from the Go Approvals team.

@pellared
Copy link
Member Author

pellared commented Jan 2, 2024

@MrAlias Sorry, I have missed that @yurishkuro is not an approver 😬

@MrAlias MrAlias added this to the v1.22.0 milestone 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.

baggage: Member.String should escape only the characters that MUST be escaped
4 participants