Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.3k
Open
Description
Bug report
Callingsys.intern() on a string that's not interned acquires the interpreter-wideinterned_mutex. This can lead to scaling bottlenecks either due to explicitsys.intern() calls or indirectly becausePyObject_SetAttr calls_PyUnicode_InternMortal.
We should avoid the lock acquisition if there is an interned copy already present in theinterned_dict.
For example:
_ATTR_PREFIX="bench"@register_benchmarkdefsetattr_non_interned():prefix=_ATTR_PREFIXobj=MyObject()for_inrange(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.