Repository navigation
gh-158660: Optimize list.extend() for frozenset and frozendict - #163008
Conversation
Do not lock frozenset and frozendict to increase threading scalability and performance. Previously, frozendict used the slow generic list_extend_iter_lock_held() code path: use the iterator protocol. Add test_extend_types() to test_list.
|
I'm not sure list.extend(frozenset) makes sense. Lists are for ordered items, but frozenset is unordered. For frozendict, it may makes sense as we guarantee key insertion order (I hope it's the case btw, I haven't checked), but I don't know why we should optimize it for frozenset. |
|
Oh, currently frozenset methods requires to lock the frozenset. I wrote #163017 to allow calling frozenset methods without locking. Once the other PR will be merged, this PR should be rebased on top of it. |
list.extend() already has a fast-path for I checked which code calls list.extend(set) in the stdlib:
Yeah, I was also surprised that it's actually used, but it is used :-)
The two |
|
Ah I see, so it's not a new change. Well I guess it makes sense then though I wonder why we have the special case in the first place (like historically) |
According to the Git history, list.extend() got a fast-path for set and frozenset with the PR gh-116657 / commit 3325699: The commit also added cc @corona10 |
|
@picnixz: So what do you think about this change? Are you ok with it? The change was suggested by @encukou on my first PR adding PyListBuilder API: #160127 (comment). |
|
Oh yes I am ok, I was surprised by the title first actually! |
|
Do not lock frozenset and frozendict to increase threading scalability and performance.
Previously, frozendict used the slow generic
list_extend_iter_lock_held() code path: use the iterator protocol.
Add test_extend_types() to test_list.
PyListBuilderC API to solvePyList_SetItem()performance issue on the free-threaded build #158660