gh-131586: Avoid refcount contention in context managers (gh-131851)

This avoid reference count contention in the free threading build
when calling special methods like `__enter__` and `__exit__`.
This commit is contained in:
Sam Gross 2025-04-21 15:54:25 -04:00 committed by GitHub
parent 8dfa840773
commit da53660f35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 247 additions and 207 deletions

View file

@ -65,6 +65,19 @@ def object_lookup_special():
for i in range(N):
round(i / N)
class MyContextManager:
def __enter__(self):
pass
def __exit__(self, exc_type, exc_value, traceback):
pass
@register_benchmark
def context_manager():
N = 1000 * WORK_SCALE
for i in range(N):
with MyContextManager():
pass
@register_benchmark
def mult_constant():
x = 1.0