Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132042: Prebuild mro_dict for find_name_in_mro to speedup class creation#132618

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
sergey-miryanov wants to merge27 commits intopython:main
base:main
Choose a base branch
Loading
fromsergey-miryanov:gh-132042-precalc-mro-dict
Open
Changes from1 commit
Commits
Show all changes
27 commits
Select commitHold shift + click to select a range
197615e
Prebuild mro_dict for find_name_in_mro
sergey-miryanovApr 6, 2025
b7842e0
Simplify find_name_in_mro_new and add some comments
sergey-miryanovApr 16, 2025
a7a978c
Fix comment for find_namd_in_mro becase it returns strong ref now
sergey-miryanovApr 16, 2025
b870751
Merge branch 'main' into gh-132042-precalc-mro-dict
sergey-miryanovApr 17, 2025
a64d3a0
Allow fixup_slot_dispatchers fails
sergey-miryanovApr 18, 2025
7e067e3
Merge branch 'main' into gh-132042-precalc-mro-dict
sergey-miryanovApr 18, 2025
88a19d5
Revert "Allow fixup_slot_dispatchers fails"
sergey-miryanovApr 18, 2025
860fbe7
Update comment about prebuild MRO-dict
sergey-miryanovApr 18, 2025
52617cb
Merge branch 'main' into gh-132042-precalc-mro-dict
sergey-miryanovApr 19, 2025
d46f493
Allow fixup_slot_dispatchers fails
sergey-miryanovApr 22, 2025
8f7750e
Fix test_type_lookup_mro_reference test because it raises exception w…
sergey-miryanovApr 22, 2025
0d17713
Merge branch 'main' into gh-132042-precalc-mro-dict
sergey-miryanovApr 22, 2025
7f4c9c7
Update comment about building MRO dict
sergey-miryanovApr 22, 2025
0d5375e
Merge branch 'main' into gh-132042-precalc-mro-dict
sergey-miryanovApr 29, 2025
90296f0
Merge branch 'gh-132042-precalc-mro-dict' of github.com:sergey-miryan…
sergey-miryanovApr 29, 2025
26bafbf
Remove END_TYPE_LOCK from fixup_slot_dispatchers
sergey-miryanovApr 29, 2025
23aaee0
Merge branch 'main' into gh-132042-precalc-mro-dict
sergey-miryanovApr 29, 2025
74eabaf
Trying to fix build
sergey-miryanovApr 29, 2025
63ab044
Fix build
sergey-miryanovApr 29, 2025
da778df
Merge branch 'main' into gh-132042-precalc-mro-dict
sergey-miryanovApr 29, 2025
b9a1208
Fix merge conflicts
sergey-miryanovApr 29, 2025
39f987b
Fix merge conflicts
sergey-miryanovApr 29, 2025
ede356d
Merge branch 'main' into gh-132042-precalc-mro-dict
sergey-miryanovJun 24, 2025
b3874ce
Replace lock with assert
sergey-miryanovJun 24, 2025
9cd3902
Fix fixup_slot_dispatchers definition
sergey-miryanovJun 24, 2025
ce1ed2c
Revert "Replace lock with assert"
sergey-miryanovJun 24, 2025
c71c8be
Replace lock with assert
sergey-miryanovJun 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Merge branch 'main' intogh-132042-precalc-mro-dict
  • Loading branch information
@sergey-miryanov
sergey-miryanov committedApr 29, 2025
commitda778df5b508010cdb12d5e5efa763e757ba30db
29 changes: 13 additions & 16 deletionsObjects/typeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5663,9 +5663,9 @@ find_name_in_mro(PyTypeObject *type, PyObject *name, int *error)
This returns a strong reference, and might set an exception.
'error' is set to: -1: error with exception; 0: ok */
static PyObject *
find_name_in_mro_new(PyTypeObject *type,PyObject *mro_dict, PyObject *name, int *error)
find_name_in_mro_new(PyObject *mro_dict, PyObject *name, int *error)
{
ASSERT_WORLD_STOPPED_OR_NEW_TYPE(type);
ASSERT_TYPE_LOCK_HELD();

PyObject *res = NULL;
if (PyDict_GetItemRef(mro_dict, name, &res) < 0) {
Expand DownExpand Up@@ -5697,19 +5697,14 @@ is_dunder_name(PyObject *name)
static PyObject *
update_cache(struct type_cache_entry *entry, PyObject *name, unsigned int version_tag, PyObject *value)
{
_Py_atomic_store_uint32_relaxed(&entry->version, version_tag);
_Py_atomic_store_ptr_relaxed(&entry->value, value); /* borrowed */
assert(_PyASCIIObject_CAST(name)->hash != -1);
OBJECT_STAT_INC_COND(type_cache_collisions, entry->name != Py_None && entry->name != name);
// We're releasing this under the lock for simplicity sake because it's always a
// exact unicode object or Py_None so it's safe to do so.
PyObject *old_name = entry->name;
_Py_atomic_store_ptr_relaxed(&entry->name, Py_NewRef(name));
// We must write the version last to avoid _Py_TryXGetStackRef()
// operating on an invalid (already deallocated) value inside
// _PyType_LookupRefAndVersion(). If we write the version first then a
// reader could pass the "entry_version == type_version" check but could
// be using the old entry value.
_Py_atomic_store_uint32_release(&entry->version, version_tag);
return old_name;
}

Expand DownExpand Up@@ -5786,7 +5781,7 @@ _PyType_LookupStackRefAndVersion(PyTypeObject *type, PyObject *name, _PyStackRef
// synchronize-with other writing threads by doing an acquire load on the sequence
while (1) {
uint32_t sequence = _PySeqLock_BeginRead(&entry->sequence);
uint32_t entry_version =_Py_atomic_load_uint32_acquire(&entry->version);
uint32_t entry_version =_Py_atomic_load_uint32_relaxed(&entry->version);
uint32_t type_version = _Py_atomic_load_uint32_acquire(&type->tp_version_tag);
if (entry_version == type_version &&
_Py_atomic_load_ptr_relaxed(&entry->name) == name) {
Expand DownExpand Up@@ -5833,14 +5828,11 @@ _PyType_LookupStackRefAndVersion(PyTypeObject *type, PyObject *name, _PyStackRef
int has_version = 0;
unsigned int assigned_version = 0;
BEGIN_TYPE_LOCK();
// We must assign the version before doing the lookup. If
// find_name_in_mro() blocks and releases the critical section
// then the type version can change.
res = find_name_in_mro(type, name, &error);
if (MCACHE_CACHEABLE_NAME(name)) {
has_version = assign_version_tag(interp, type);
assigned_version = type->tp_version_tag;
}
res = find_name_in_mro(type, name, &error);
END_TYPE_LOCK();

/* Only put NULL results into cache if there was no error. */
Expand DownExpand Up@@ -11203,7 +11195,7 @@ update_one_slot(PyTypeObject *type, pytype_slotdef *p, PyObject *mro_dict)
if (mro_dict == NULL) {
descr = find_name_in_mro(type, p->name_strobj, &error);
} else {
descr = find_name_in_mro_new(type,mro_dict, p->name_strobj, &error);
descr = find_name_in_mro_new(mro_dict, p->name_strobj, &error);
}
if (descr == NULL) {
if (error == -1) {
Expand DownExpand Up@@ -11350,10 +11342,13 @@ update_slot(PyTypeObject *type, PyObject *name)
static int
fixup_slot_dispatchers(PyTypeObject *type)
{
ASSERT_WORLD_STOPPED_OR_NEW_TYPE(type);

int res = 0;

// This lock isn't strictly necessary because the type has not been
// exposed to anyone else yet, but update_ont_slot calls find_name_in_mro
// where we'd like to assert that the type is locked.
BEGIN_TYPE_LOCK();

PyObject *mro = Py_NewRef(lookup_tp_mro(type));

// Build MRO dict. We build it in bottom-top manner,
Expand DownExpand Up@@ -11394,6 +11389,8 @@ fixup_slot_dispatchers(PyTypeObject *type)
finish:
Py_XDECREF(mro_dict);
Py_DECREF(mro);

END_TYPE_LOCK();
return res;
}

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view thefull changes here.

[8]ページ先頭

©2009-2025 Movatter.jp