perf(api): add getGlobal fast-path - #6956
Open
legendecas wants to merge 1 commit into
Open
Conversation
Pull request dashboard statusWaiting on reviewers · refreshed 2026-07-28 23:30 UTC Review the latest changes. Status above doesn't look right?
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6956 +/- ##
=======================================
Coverage 95.07% 95.07%
=======================================
Files 409 409
Lines 14256 14262 +6
Branches 3267 3266 -1
=======================================
+ Hits 13554 13560 +6
Misses 702 702
🚀 New features to boost your workflow:
|
legendecas
force-pushed
the
bench/api/get-global
branch
from
July 28, 2026 20:24
6f6d0ea to
a642e81
Compare
legendecas
force-pushed
the
bench/api/get-global
branch
from
July 28, 2026 20:34
a642e81 to
643e5a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which problem is this PR solving?
In examples, documents and instrumentations, we use patterns like
api.context.active()andapi.trace.setSpan(...)a lot. However, theisCompatiblecheck could be expensive even if it caches the version with aSet.hasif the call count accumulates.This adds a fast-path where the global api is rarely modified, as API registration happens way less frequent than
getGlobal(). API registration usually only happens at startup time once.One caveat is that this assumes that no one tries to modify the
global[GLOBAL_OPENTELEMETRY_API_KEY].versionon the same objectglobal[GLOBAL_OPENTELEMETRY_API_KEY]. The@opentelemetry/apipackage itself does not do this, so the fast-path is compatible with existing@opentelemetry/apiversions. This also seals theglobal[GLOBAL_OPENTELEMETRY_API_KEY].versionto be non-writable and non-configurable to make sure that fast-path is always correct.Type of change
How Has This Been Tested?
nullto theglobal[GLOBAL_OPENTELEMETRY_API_KEY].Checklist: