Skip to content

perf(sdk-trace-base): optimize Span.{addEvent,addLink} performance#6516

Merged
dyladan merged 2 commits intoopen-telemetry:mainfrom
daniellockyer:perf/span-bench-addEvent-addLink
Mar 23, 2026
Merged

perf(sdk-trace-base): optimize Span.{addEvent,addLink} performance#6516
dyladan merged 2 commits intoopen-telemetry:mainfrom
daniellockyer:perf/span-bench-addEvent-addLink

Conversation

@daniellockyer
Copy link
Copy Markdown
Contributor

Which problem is this PR solving?

Improves the performance of Span.{addEvent,addLink} by applying the same changes as b97b488 (by @AbhiPrasad) and #6514 (by me)

Before:

addEvent (128 attributes) x 9,581 ops/sec ±0.47% (99 runs sampled)
addLink (128 attributes) x 9,481 ops/sec ±0.14% (101 runs sampled)

After:

addEvent (128 attributes) x 76,473 ops/sec ±0.63% (95 runs sampled)
addLink (128 attributes) x 76,953 ops/sec ±0.11% (102 runs sampled)

refs #6100

Short description of the changes

  • Remove use of Object.entries, as this is not performant as a for-in loop
  • Remove use of Object.keys(..).length in a loop and use a variable to track count
  • Add new benchmarks for these changes.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Tests still pass, and you can see benchmarks above

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@daniellockyer daniellockyer requested a review from a team as a code owner March 21, 2026 10:50
@daniellockyer daniellockyer force-pushed the perf/span-bench-addEvent-addLink branch from 6a36026 to d9cb962 Compare March 21, 2026 10:50
Copy link
Copy Markdown
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

nice!

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.73%. Comparing base (e9831e7) to head (ae7f691).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/opentelemetry-sdk-trace-base/src/Span.ts 86.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6516      +/-   ##
==========================================
- Coverage   95.75%   95.73%   -0.02%     
==========================================
  Files         364      364              
  Lines       12096    12104       +8     
  Branches     2885     2887       +2     
==========================================
+ Hits        11582    11588       +6     
- Misses        514      516       +2     
Files with missing lines Coverage Δ
packages/opentelemetry-sdk-trace-base/src/Span.ts 98.31% <86.66%> (-0.82%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@daniellockyer
Copy link
Copy Markdown
Contributor Author

Fixed my conflicts from main 🙂

@dyladan dyladan added this pull request to the merge queue Mar 23, 2026
Merged via the queue into open-telemetry:main with commit dc93ed4 Mar 23, 2026
27 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Mar 23, 2026

Thank you for your contribution @daniellockyer! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

@daniellockyer daniellockyer deleted the perf/span-bench-addEvent-addLink branch March 23, 2026 19:40
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