python / cpython

The Python programming language
https://www.python.org
Other
63.66k stars 30.49k forks source link

gh-115999: Add free-threaded specialization for `STORE_SUBSCR` #127169

Open colesbury opened 3 days ago

colesbury commented 3 days ago

The specialization only depends on the type, so no special thread-safety considerations there.

STORE_SUBSCR_LIST_INT needs to lock the list before modifying it.

_PyDict_SetItem_Take2 already internally locks the dictionary using a critical section.

colesbury commented 3 days ago

@corona10 - I put my name down next to STORE_ATTR, but then got confused and worked on STORE_SUBSCR instead. Sorry!

colesbury commented 3 days ago

(STORE_ATTR is up for grabs)

corona10 commented 3 days ago

I put my name down next to STORE_ATTR, but then got confused and worked on STORE_SUBSCR instead. Sorry!

Race condition with the wrong lock :) Fine, thank you for the work, I've updated the list of issues.

colesbury commented 13 hours ago

Performance difference is marginal: 1.00x faster (but 99.99% likely to be faster)

https://github.com/facebookexperimental/free-threading-benchmarking/blob/main/results/bm-20241122-3.14.0a2%2B-2b63929-NOGIL/bm-20241122-vultr-x86_64-colesbury-gh_115999_store_subs-3.14.0a2%2B-2b63929-vs-base.md

I think it's worth doing even if the perf is neutral just to minimize divergence with the default (GIL) build.