Repository navigation
Conversation
Signed-off-by: skulitom <artemskulimovskiy@gmail.com>
This branch has not been deployed
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.
Repeated
labels(...).inc()andlabels(...).observe()calls currently acquire the parent metric lock even when their labeled child already exists. An existing-child lookup also waits for unrelated child construction to finish.Return an existing child with a single dictionary lookup after the existing validation/normalization. On a miss, retain the locked recheck and child creation. Removal and collection keep their existing synchronization. The single read avoids a check-then-read race; Python documents this dictionary operation as atomic, including in free-threaded builds: https://docs.python.org/3/builtins/threadsafety.html#thread-safety-for-dict-objects.
Fixes #1215. @csmarchbanks
Validation:
tox -e flake8,isort,mypy: all passed.Local benchmark (Linux/WSL, CPython 3.14.8, 32 logical CPUs): median of five samples, 50,000 operations per thread, one pre-created labelset per thread. The before/after runs used the same interpreter and separate source trees, without simultaneous test runs. The free-threaded process reported the GIL disabled. Throughput below is million operations/second, with eight threads:
labels()labels().inc()labels().observe(0.2).inc()(control)These are positional-label microbenchmarks, not an application-wide speedup claim. Caching a child remains faster. The script also measures one and four threads; at one thread,
labels().inc()improved from 1.545 to 1.837 Mops/s on default Python and 1.147 to 1.395 Mops/s on free-threaded Python. Unchanged control measurements varied by up to about 9% across the thread counts.Reproduction script
Save as
benchmark_labels.pyoutside the checkout and run with each source revision onPYTHONPATH, using the same interpreter:AI assistance: implementation, tests, and benchmark execution were prepared with Codex.