Skip to content

gh-124642: Dictionaries aren't marking objects as weakref'd #124643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 30, 2024

Conversation

DinoV
Copy link
Contributor

@DinoV DinoV commented Sep 26, 2024

@@ -1488,7 +1488,7 @@ _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyOb
*value_addr = value;
if (value != NULL) {
assert(ix >= 0);
Py_INCREF(value);
_Py_NewRefWithLock(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have a test for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's not a great way to test this short of actually inspecting the ob_ref_shared field which isn't something we've done yet in free-threaded builds, so I'm not sure we want/need one.

The end result is just poor performance, but that's difficult to measure. It also requires a pretty particular set of circumstances to manifest, e.g. the shared ref count needs to already be 0 when we're increfing it here.

@DinoV DinoV force-pushed the nogil_dict_weakref branch from a4820a6 to 6c286b2 Compare September 27, 2024 17:49
@DinoV DinoV marked this pull request as ready for review September 27, 2024 19:46
@DinoV DinoV merged commit 077e7ef into python:main Sep 30, 2024
40 checks passed
@DinoV DinoV added the needs backport to 3.13 bugs and security fixes label Sep 30, 2024
@miss-islington-app
Copy link

Thanks @DinoV for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 30, 2024
…thonGH-124643)

Dictionaries aren't marking objects as weakref'd
(cherry picked from commit 077e7ef)

Co-authored-by: Dino Viehland <dinoviehland@meta.com>
@bedevere-app
Copy link

bedevere-app bot commented Sep 30, 2024

GH-124798 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Sep 30, 2024
Yhg1s pushed a commit that referenced this pull request Sep 30, 2024
…H-124643) (#124798)

gh-124642: Dictionaries aren't marking objects as weakref'd (GH-124643)

Dictionaries aren't marking objects as weakref'd
(cherry picked from commit 077e7ef)

Co-authored-by: Dino Viehland <dinoviehland@meta.com>
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.

3 participants