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

Change Options to accept type not pointer #2558

Merged
merged 8 commits into from
Feb 1, 2022

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Jan 26, 2022

Resolves #2065, part of the resolution proposed in #2402.

Testing Performance

Removed an allocation for each config in trace package.

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/trace
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkNewTracerConfig-8      	123097324	         9.721 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewSpanStartConfig-8   	 4853584	       246.9 ns/op	     160 B/op	       2 allocs/op
BenchmarkNewSpanEndConfig-8     	26190746	        44.25 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewEventConfig-8       	 9757192	       120.4 ns/op	      64 B/op	       1 allocs/op
PASS

Originally:

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/trace
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkNewTracerConfig-8      	26852644	        41.99 ns/op	      32 B/op	       1 allocs/op
BenchmarkNewSpanStartConfig-8   	 5201097	       224.6 ns/op	     256 B/op	       3 allocs/op
BenchmarkNewSpanEndConfig-8     	19803043	        58.47 ns/op	      96 B/op	       1 allocs/op
BenchmarkNewEventConfig-8       	10573510	       111.2 ns/op	     128 B/op	       2 allocs/op
PASS

Add benchmark to show allocation improvement.
@MrAlias MrAlias added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Jan 26, 2022
@codecov
Copy link

codecov bot commented Jan 26, 2022

Codecov Report

Merging #2558 (4893e07) into main (e58070a) will decrease coverage by 0.0%.
The diff coverage is 81.9%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #2558     +/-   ##
=======================================
- Coverage   76.0%   76.0%   -0.1%     
=======================================
  Files        174     174             
  Lines      12091   12193    +102     
=======================================
+ Hits        9194    9271     +77     
- Misses      2652    2677     +25     
  Partials     245     245             
Impacted Files Coverage Δ
metric/config.go 65.9% <50.0%> (-1.6%) ⬇️
exporters/jaeger/uploader.go 48.5% <57.1%> (-0.7%) ⬇️
...xporters/otlp/otlpmetric/otlpmetricgrpc/options.go 76.4% <66.6%> (-1.8%) ⬇️
exporters/otlp/otlptrace/otlptracegrpc/options.go 76.4% <66.6%> (-1.8%) ⬇️
exporters/zipkin/zipkin.go 72.3% <71.4%> (-0.5%) ⬇️
trace/config.go 64.1% <76.3%> (+0.4%) ⬆️
exporters/stdout/stdoutmetric/config.go 84.3% <77.7%> (-1.4%) ⬇️
...ers/otlp/otlpmetric/internal/otlpconfig/options.go 76.0% <81.5%> (+0.3%) ⬆️
...ters/otlp/otlptrace/internal/otlpconfig/options.go 76.0% <81.5%> (+0.3%) ⬆️
...xporters/otlp/otlpmetric/otlpmetrichttp/options.go 70.5% <87.5%> (+1.3%) ⬆️
... and 17 more

@MrAlias MrAlias marked this pull request as ready for review January 26, 2022 23:31
@MrAlias MrAlias changed the title [WIP] Change Options to accept type not pointer Change Options to accept type not pointer Jan 26, 2022
@MrAlias
Copy link
Contributor Author

MrAlias commented Jan 27, 2022

Looking at benchstat this might increase the operation computation time. We need to explore why and potentially improve our benchmarks to show if this is a worth while change.

@MadVikingGod
Copy link
Contributor

As promised here are the benchstat breakdown. As I mentioned in the sig meeting allocations do go down accross the board, but there is an actual time increase for NewSpanStartConfig.

name                  old time/op    new time/op    delta
NewTracerConfig-4       53.4ns ±15%    11.2ns ± 7%   -79.04%  (p=0.000 n=10+9)
NewSpanStartConfig-4     279ns ±16%     319ns ±19%   +14.01%  (p=0.004 n=9+9)
NewSpanEndConfig-4      72.3ns ±19%    50.1ns ± 2%   -30.78%  (p=0.000 n=9+9)
NewEventConfig-4         137ns ± 6%     150ns ± 5%    +9.37%  (p=0.000 n=10+10)

name                  old alloc/op   new alloc/op   delta
NewTracerConfig-4        32.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
NewSpanStartConfig-4      256B ± 0%      160B ± 0%   -37.50%  (p=0.000 n=10+10)
NewSpanEndConfig-4       96.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
NewEventConfig-4          128B ± 0%       64B ± 0%   -50.00%  (p=0.000 n=10+10)

name                  old allocs/op  new allocs/op  delta
NewTracerConfig-4         1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
NewSpanStartConfig-4      3.00 ± 0%      2.00 ± 0%   -33.33%  (p=0.000 n=10+10)
NewSpanEndConfig-4        1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
NewEventConfig-4          2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)

Copy link
Contributor

@jmacd jmacd left a comment

Choose a reason for hiding this comment

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

🚀

@MadVikingGod MadVikingGod merged commit bd817df into open-telemetry:main Feb 1, 2022
@MrAlias MrAlias deleted the apply-refactor branch February 1, 2022 22:22
MrAlias added a commit that referenced this pull request Mar 21, 2022
* Allow setting the Sampler via environment variables (#2305)

* Add changelog entry.

* Replace t.Setenv with internaltest/SetEnvVariables for Go <= 1.6.

* Handle the lack of a sampler argument without logging errors.

* Add additional test cases and error checks.

* Refactor documentation.

Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>

* emitBatchOverhead should only be used for splitting spans into batches (#2512)

* emitBatchOverhead should only be used for splitting spans into batches (#2503)

* limit max packet size parameter

* Add additional errors types, simplify abstractions and error handling

* Make error comparisons less fragile.

* Fix typo in jaeger example (#2524)

* Fix some typos in docs for Go libraries (#2520)

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Fix getting-started.md Run function (#2527)

* Fix getting-started.md Run function, it assigns this new context to a variable shared between connections in to accept loop. Thus creating a growing chain of contexts. so every calculate fibonacci request, all spans in a trace.

* add a comment explaining the reason for that new variable

* update example fib

* Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 across the project (#2545)

* update go-cmp to 0.5.7

* fixes go.sums

Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>

* Un-escape url coding when parsing baggage. (#2529)

* un-escape url coding when parsing baggage.

* Added changelog

Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Bump go.opentelemetry.io/proto/otlp from 0.11.0 to 0.12.0 (#2546)

* Update go.opentelemetry.io/proto/otlp to v0.12.0

* Changelog

* Update CHANGELOG.md

Fix's md linting

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Remove unused sdk/internal/santize (#2549)

* Add links to code examples and docs (#2551)

* Bump github.com/prometheus/client_golang from 1.11.0 to 1.12.0 in /exporters/prometheus (#2541)

* Bump github.com/prometheus/client_golang in /exporters/prometheus

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.11.0 to 1.12.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](prometheus/client_golang@v1.11.0...v1.12.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* go mod tidy

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Optimize evictedQueue implementation and use (#2556)

* Optimize evictedQueue impl and use

Avoid unnecessary allocations in the recordingSpan by using an
evictedQueue type instead of a pointer to one.

Lazy allocate the evictedQueue queue to prevent unnecessary operations
for spans without any use of the queue.

Document the evictedQueue

* Fix grammar

* Add env support for batch span processor (#2515)

* Add env support for batch span processor

* Update changelog

* lint

* Bump golang.org/x/tools from 0.1.8 to 0.1.9 in /internal/tools (#2566)

* Bump golang.org/x/tools from 0.1.8 to 0.1.9 in /internal/tools

Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.1.8 to 0.1.9.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](golang/tools@v0.1.8...v0.1.9)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Auto-fix go.sum changes in dependent modules

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>

* Bump github.com/golangci/golangci-lint from 1.43.0 to 1.44.0 in /internal/tools (#2567)

* Bump github.com/golangci/golangci-lint in /internal/tools

Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](golangci/golangci-lint@v1.43.0...v1.44.0)

---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Auto-fix go.sum changes in dependent modules

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>

* Bump github.com/prometheus/client_golang from 1.12.0 to 1.12.1 in /exporters/prometheus (#2570)

* Bump github.com/prometheus/client_golang in /exporters/prometheus

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.12.0 to 1.12.1.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](prometheus/client_golang@v1.12.0...v1.12.1)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Auto-fix go.sum changes in dependent modules

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>

* Fix TestBackoffRetry in otlp/internal/retry package (#2562)

* Fix TestBackoffRetry in otlp retry pkg

The delay of the retry is within two times a randomization factor (the
back-off time is delay * random number within [1 - factor, 1 + factor].
This means the waitFunc in TestBackoffRetry needs to check the delay is
within an appropriate delta, not equal to configure initial delay.

* Fix delta value

* Fix delta

Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>

* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /exporters/otlp/otlptrace (#2568)

* Bump google.golang.org/grpc in /exporters/otlp/otlptrace

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.43.0...v1.44.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Auto-fix go.sum changes in dependent modules

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>

* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /example/otel-collector (#2565)

* Bump google.golang.org/grpc in /example/otel-collector

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.43.0...v1.44.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Auto-fix go.sum changes in dependent modules

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>

* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /exporters/otlp/otlpmetric (#2572)

* Bump google.golang.org/grpc in /exporters/otlp/otlpmetric

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.43.0...v1.44.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Auto-fix go.sum changes in dependent modules

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>

* Change Options to accept type not pointer (#2558)

* Change trace options to accept type not pointer

Add benchmark to show allocation improvement.

* Update CONTRIBUTING.md guidelines

* Update all Option iface

* Fix grammar in CONTRIBUTING

* Do not store TracerProvider or Tracer fields in SDK recordingSpan (#2575)

* Do not store TracerProvider fields in span

Instead of keeping a reference to the span's Tracer, and therefore also
it's TracerProvider, and the associated resource and spanLimits just
keep the reference to the Tracer. Refer to the TracerProvider fields
when needed instead.

* Make span refer to the inst lib via the Tracer

Instead of holding a field in the span, refer to the field in the parent
Tracer.

* [website_docs] fix page meta-links (#2580)

Contributes to open-telemetry/opentelemetry.io#1096

/cc @cartermp @austinlparker

* Validate members once, in `NewMember` (#2522)

* use NewMember, or specify if the member is not validated when creating new ones

* expect members to already be validated when creating a new package

* add changelog entry

* add an isEmpty field to member and property for quick validation

* rename isEmpty to hasData

So by default, an empty struct really is marked as having no data

* Update baggage/baggage_test.go

Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>

* don't validate the member in parseMember, we alredy ran that validation

We also don't want to use NewMember, as that runs the property
validation again, making the benchmark quite slower

* move changelog entry to the fixed section

* provide the member/property data when returning an invalid error

Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>

* Fix link to Zipkin exporter (#2581)

Currently it is linked to the old package that was moved.

* Unexport EnvBatchSpanProcessor* constants (#2583)

* Move BSP env support to internal

* Use pkg name

* Update env test

* Use internal/env in sdk/trace

* Avoid an extra allocation in applyTracerProviderEnvConfigs.

* Add additional errors for ratio > 1.0.

* Add test cases for ratio > 1.0.

* Update CHANGELOG.md

Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
Co-authored-by: jaychung <ken8203@gmail.com>
Co-authored-by: Ben Wells <b.v.wells@gmail.com>
Co-authored-by: Jeremy Kaplan <jeremy@stytch.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: thinkgo <49174849+thinkgos@users.noreply.github.com>
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Chao Weng <19381524+sincejune@users.noreply.github.com>
Co-authored-by: Patrice Chalin <chalin@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
@pellared pellared added this to the untracked milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid unnecessary heap allocation in NewSpanStartConfig
5 participants