Skip to content

Conversation

@DinoV
Copy link
Contributor

@DinoV DinoV commented Feb 14, 2025

This is just a small tweak to make __new__ be deferred so that it can be cached in the specializing interpreter. __new__'s wrapper is small, doesn't hold onto other things except the circular reference between it and the type, meaning the GC reclaims it anyways. We may as well defer it and be able to load cached values.

https://github.com/facebookexperimental/free-threading-benchmarking/blob/main/results/bm-20250213-3.14.0a5%2B-82e19c2-NOGIL/bm-20250213-vultr-x86_64-DinoV-deferred_dunder_new-3.14.0a5%2B-82e19c2-vs-base.md

}
r = PyDict_SetItem(dict, &_Py_ID(__new__), func);
if (!r) {
_PyObject_SetDeferredRefcount(func);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this up before the PyDict_SetItem? I'd rather set the deferred reference counting bit before exposing the function to avoid any race conditions on ob_gc_bits.

@DinoV DinoV force-pushed the deferred_dunder_new branch from 82e19c2 to 48c0e94 Compare February 14, 2025 17:45
Copy link
Contributor

@mpage mpage left a comment

Choose a reason for hiding this comment

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

Nice! The job failure looks like an infra error that's unrelated to the PR.

@DinoV DinoV merged commit 5a586c3 into python:main Feb 14, 2025
41 checks passed
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