FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-112075: _Py_dict_lookup needs to lock shared keys by DinoV · Pull Request #117528 · python/cpython · GitHub

/ cpython Public

gh-112075: _Py_dict_lookup needs to lock shared keys - #117528

Merged
DinoV merged 8 commits into
python:mainfrom
DinoV:nogil_dict_shared_key_insert
Apr 25, 2024
Merged

gh-112075: _Py_dict_lookup needs to lock shared keys#117528
DinoV merged 8 commits into
python:mainfrom
DinoV:nogil_dict_shared_key_insert

Conversation

DinoV commented Apr 3, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

_Py_dict_lookup needs to lock the shared keys if we have a split dictionary. If we're looking up with a non-exact unicode we need to also incref the keys as the lookup could mutate the keys and we could lose the last reference.

insertdict is updated to avoid contention on the shared dict lookup by calling the threadsafe unicode lookup directly and only falling back to _Py_dict_lookup if the thread safe lookup can't succeed.

DinoV requested a review from colesbury April 3, 2024 23:53
DinoV force-pushed the nogil_dict_shared_key_insert branch 2 times, most recently from c51437d to f3e3db3 Compare April 4, 2024 00:04
DinoV marked this pull request as ready for review April 4, 2024 00:35

colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks right, but I'm still seeing issues with the test that uncovered the problem. I'll investigate more today.

Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c Outdated
DinoV force-pushed the nogil_dict_shared_key_insert branch from 8942e4d to 2f5f5a1 Compare April 5, 2024 02:23
DinoV force-pushed the nogil_dict_shared_key_insert branch 10 times, most recently from 35cf56e to d580aa5 Compare April 16, 2024 01:31

colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm still looking at _Py_dict_lookup, but I think insertdict and dict_setdefault_ref_lock_held can be simpler if they handle split dictionaries early on and separate from the main code path.

Comment thread Objects/dictobject.c Outdated
DinoV force-pushed the nogil_dict_shared_key_insert branch 2 times, most recently from cfd659c to 19d1446 Compare April 24, 2024 20:30
DinoV force-pushed the nogil_dict_shared_key_insert branch from 19d1446 to a74c0ee Compare April 25, 2024 16:19

colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM other than the unused code warning in the default build

Comment thread Objects/dictobject.c
}

static Py_ssize_t
unicodekeys_lookup_unicode_threadsafe(PyDictKeysObject* dk, PyObject *key,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Unused code warning

DinoV merged commit d5df252 into python:main Apr 25, 2024
DinoV deleted the nogil_dict_shared_key_insert branch May 31, 2024 18:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL