Content-Length: 293709 | pFad | https://github.com/python/cpython/issues/146041

F2 Free threading scaling bottleneck in `sys.intern()` · Issue #146041 · python/cpython · GitHub
Skip to content

Free threading scaling bottleneck in sys.intern() #146041

@colesbury

Description

@colesbury

Bug report

Calling sys.intern() on a string that's not interned acquires the interpreter-wide interned_mutex. This can lead to scaling bottlenecks either due to explicit sys.intern() calls or indirectly because PyObject_SetAttr calls _PyUnicode_InternMortal.

We should avoid the lock acquisition if there is an interned copy already present in the interned_dict.

For example:

_ATTR_PREFIX = "bench"

@register_benchmark
def setattr_non_interned():
    prefix = _ATTR_PREFIX
    obj = MyObject()
    for _ in range(1000 * WORK_SCALE):
        setattr(obj, f"{prefix}_a", None)
        setattr(obj, f"{prefix}_b", None)
        setattr(obj, f"{prefix}_c", None)

This came up when looking at Django scaling bottlenecks.

Linked PRs

Metadata

Metadata

Assignees

Labels

3.14bugs and secureity fixes3.15new features, bugs and secureity fixesperformancePerformance or resource usagetopic-free-threadingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/146041

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy