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

[sdk] SuppressInstrumentationScope perf tweaks #4304

Merged

Conversation

CodeBlanch
Copy link
Member

@CodeBlanch CodeBlanch commented Mar 15, 2023

Changes

Tweaked the implementation of SuppressInstrumentationScope to achieve better perf.

Before...

  • We stored an int in the context slot. That int had to be boxed when scopes were created and we boxed a 0 when scopes were disposed.
  • Any time we incremented or decremented in reference counting mode we pushed a new int to the context slot which had to be boxed AND creates a new ExecutionContext.

After...

  • We store the SuppressInstrumentationScope instance itself in the context slot. That avoids the boxing and gives us storage for the reference count which we can increment/decrement freely without creating any new ExecutionContexts.

Benchmarks

Before:

Method Mean Error StdDev Gen0 Allocated
Begin 143.91 ns 2.027 ns 1.896 ns 0.0515 648 B
Enter 99.49 ns 1.226 ns 1.147 ns 0.0305 384 B

After:

Method Mean Error StdDev Gen0 Allocated
Begin 125.37 ns 1.738 ns 1.626 ns 0.0362 456 B
Enter 59.17 ns 0.710 ns 0.664 ns 0.0082 104 B

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Unit tests added/updated

@CodeBlanch CodeBlanch requested a review from a team March 15, 2023 00:10
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Merging #4304 (2c6d0e2) into main (7638d85) will decrease coverage by 0.07%.
The diff coverage is 88.57%.

❗ Current head 2c6d0e2 differs from pull request most recent head bff3687. Consider uploading reports for the commit bff3687 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4304      +/-   ##
==========================================
- Coverage   84.45%   84.39%   -0.07%     
==========================================
  Files         298      298              
  Lines       11854    11872      +18     
==========================================
+ Hits        10011    10019       +8     
- Misses       1843     1853      +10     
Impacted Files Coverage Δ
src/OpenTelemetry/SuppressInstrumentationScope.cs 90.24% <88.57%> (-9.76%) ⬇️

... and 8 files with indirect coverage changes

@CodeBlanch CodeBlanch merged commit 5aad3e0 into open-telemetry:main Mar 15, 2023
@CodeBlanch CodeBlanch deleted the suppressinstrumentation-perf branch March 15, 2023 18:29
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.

3 participants