Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
56d13fc
Prebuild mro_dict for find_name_in_mro
sergey-miryanov Apr 6, 2025
1eed75d
Preget tp_dict
sergey-miryanov Apr 6, 2025
bba66d6
Slotdefs cache
sergey-miryanov Apr 7, 2025
bac95a5
Move slotdefs_cache to interp
sergey-miryanov Apr 8, 2025
8d1f5be
Use bytes for slotdefs_cache
sergey-miryanov Apr 8, 2025
8cf19e8
Use type_slots_ptrs cache
sergey-miryanov Apr 8, 2025
b0ad875
Move slotdefs_cache init to pycore_init_builtins
sergey-miryanov Apr 8, 2025
79a165d
Create slotdefs_cache only for main interpreter
sergey-miryanov Apr 9, 2025
a853294
Do not iterate slotdefs_cache just check dups count
sergey-miryanov Apr 9, 2025
75c17fb
Add name_count to pytype_slotdef and get rid of slotdefs_cache and re…
sergey-miryanov Apr 9, 2025
fc17a68
Rename _PyType_InitSlotDefsCache to _PyType_InitSlotDefsNameCounts
sergey-miryanov Apr 9, 2025
736bca4
Get rid of type_slots_ptrs and type_slots_pname from _Py_interp_cache…
sergey-miryanov Apr 9, 2025
1341ed9
Add news entry
sergey-miryanov Apr 9, 2025
3efb9ca
Rename _PyType_InitSlotDefsNameCounts
sergey-miryanov Apr 16, 2025
a792e9d
Use
sergey-miryanov Apr 16, 2025
b6fafa9
Revert "Preget tp_dict"
sergey-miryanov Apr 16, 2025
1459c16
Revert "Prebuild mro_dict for find_name_in_mro"
sergey-miryanov Apr 16, 2025
08740af
Update _PyType_InitSlotDefs and add comment for wrapperbase.name_count
sergey-miryanov Apr 16, 2025
0370d59
Fix error message if _PyType_InitSlotDefs fails
sergey-miryanov Apr 16, 2025
7a57f7c
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov Apr 18, 2025
c2372f1
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov Apr 20, 2025
9f48eb3
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov Apr 22, 2025
17d0265
Use slotdefs_name_counts to check name duplicates
sergey-miryanov Apr 22, 2025
6d5589c
Add slotdefs_name_counts to ignored.tsv to make c-analyzer happy
sergey-miryanov Apr 22, 2025
a7af5bd
Adjust c-analyzer max_sizes
sergey-miryanov Apr 25, 2025
7f62d59
Extend error messages if too much code to c-analyzer
sergey-miryanov Apr 30, 2025
b09deaf
Revert "Extend error messages if too much code to c-analyzer"
sergey-miryanov Apr 30, 2025
04539cc
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov Apr 30, 2025
af8ce30
Apply suggestions from code review
sergey-miryanov May 1, 2025
9db0885
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov May 2, 2025
dbf869f
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov May 2, 2025
9434773
Merge branch 'gh-132042-optimize-class-creation' of github.com:sergey…
sergey-miryanov May 3, 2025
0a4c369
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov May 3, 2025
05df484
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov May 8, 2025
7a61ed3
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov Jun 24, 2025
211d043
Apply suggestions from code review
sergey-miryanov Oct 1, 2025
a4c4d8e
Merge branch 'gh-132042-optimize-class-creation' of github.com:sergey…
sergey-miryanov Oct 1, 2025
82466cc
Fix stray change
sergey-miryanov Oct 1, 2025
f0b40c7
Merge branch 'main' into gh-132042-optimize-class-creation
sergey-miryanov Oct 1, 2025
25acb4a
Fix news entry
sergey-miryanov Oct 1, 2025
5db0944
Apply suggestions from code review
sergey-miryanov Oct 2, 2025
b185436
Fix build
sergey-miryanov Oct 2, 2025
c1884f5
Update Objects/typeobject.c
sergey-miryanov Oct 3, 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
Prev Previous commit
Next Next commit
Use type_slots_ptrs cache
  • Loading branch information
sergey-miryanov committed Apr 8, 2025
commit 8cf19e8252700e91ce00470f7f8a3d63f65c2ccb
67 changes: 34 additions & 33 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -11005,22 +11005,15 @@ slotptr(PyTypeObject *type, int ioffset)
return (void **)ptr;
}

/* Return a slot pointer for a given name, but ONLY if the attribute has
exactly one slot function. The name must be an interned string. */
static void **
resolve_slotdups(PyTypeObject *type, PyObject *name)
static int
fill_type_slots_cache_from_slotdefs_cache(PyInterpreterState *interp,
PyObject *name)
{
PyInterpreterState *interp = _PyInterpreterState_GET();

/* XXX Maybe this could be optimized more -- but is it worth it? */
void **res, **ptr;
res = NULL;
#define ptrs _Py_INTERP_CACHED_OBJECT(interp, type_slots_ptrs)

int rc = 0;
PyObject *cache = Py_XNewRef(interp->cached_objects.slotdefs_cache);
if (cache) {
int rc = 0;
// Py_BEGIN_CRITICAL_SECTION(cache);

PyObject* bytes=NULL;
rc = PyDict_GetItemRef(cache, name, &bytes);
if (rc > 0) {
Expand All @@ -11033,53 +11026,61 @@ resolve_slotdups(PyTypeObject *type, PyObject *name)
assert(n >= 0);
assert(n < MAX_EQUIV);

uint8_t i;
for(i = 0; i < n; i++) {
pytype_slotdef **pp = ptrs;
for(uint8_t i = 0; i < n; i++) {
uint8_t idx = data[i + 1];
assert (idx < Py_ARRAY_LENGTH(slotdefs));

pytype_slotdef *x = &slotdefs[idx];
ptr = slotptr(type, x->offset);
if (ptr == NULL || *ptr == NULL) {
continue;
}
if (res != NULL) {
res = NULL;
break;
}
res = ptr;
*pp++ = &slotdefs[idx];
}
*pp = NULL;

Py_DECREF(bytes);
} else if (rc < 0) {
PyErr_Clear();
}

Py_DECREF(cache);
// Py_END_CRITICAL_SECTION();
if (rc > 0) {
return res;
}
}

return rc;

#undef ptrs
}

/* Return a slot pointer for a given name, but ONLY if the attribute has
exactly one slot function. The name must be an interned string. */
static void **
resolve_slotdups(PyTypeObject *type, PyObject *name)
{
/* XXX Maybe this could be optimized more -- but is it worth it? */

/* pname and ptrs act as a little cache */
PyInterpreterState *interp = _PyInterpreterState_GET();
#define pname _Py_INTERP_CACHED_OBJECT(interp, type_slots_pname)
#define ptrs _Py_INTERP_CACHED_OBJECT(interp, type_slots_ptrs)
pytype_slotdef *p, **pp;
void **res, **ptr;

if (pname != name) {
/* Collect all slotdefs that match name into ptrs. */
pname = name;
pp = ptrs;
for (p = slotdefs; p->name_strobj; p++) {
if (p->name_strobj == name)
*pp++ = p;

int rc = fill_type_slots_cache_from_slotdefs_cache(interp, name);
if (rc <= 0) {
pp = ptrs;
for (p = slotdefs; p->name_strobj; p++) {
if (p->name_strobj == name)
*pp++ = p;
}
*pp = NULL;
}
*pp = NULL;
}

/* Look in all slots of the type matching the name. If exactly one of these
has a filled-in slot, return a pointer to that slot.
Otherwise, return NULL. */
res = NULL;
for (pp = ptrs; *pp; pp++) {
ptr = slotptr(type, (*pp)->offset);
if (ptr == NULL || *ptr == NULL)
Expand Down