opentelemetry-sdk: reduce lock contention in attributes#5298
Draft
codeboten wants to merge 1 commit into
Draft
Conversation
There are a few improvements here: - set_attributes was double locking (once in set_attributes and once in __setitem__. This change updates the call to a private _setitem_locked for set_attributes once the lock has been obtained - __iter__ doesn't use a lock if the BoundedAttributes's instantiated as immutable - _worker_awaken was being set even when it's already set, adding a check in emit to avoid unnecessary calls Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
herin049
reviewed
Jun 12, 2026
| if value is None: | ||
| return | ||
| def _setitem_locked(self, key: str, value: types.AnyValue) -> None: | ||
| if self.maxlen is not None and self.maxlen == 0: |
Contributor
There was a problem hiding this comment.
Can't lines 284-295 be moved out of the critical section?
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.
Description
There are a few improvements here:
set_attributeswas double locking (once inset_attributesand once in__setitem__. This change updates the call to a private_setitem_lockedforset_attributesonce the lock has been obtained__iter__doesn't use a lock if theBoundedAttributes's instantiated as immutable_worker_awakenwas being set even when it's already set, adding a check in emit to avoid unnecessary callsType of change
Please delete options that are not relevant.
How Has This Been Tested?
Ran unit tests to validate functionality was still passing and ran benchmarks including a new test to try and capture GIL contention. See the results below:
Does This PR Require a Contrib Repo Change?
Checklist: