Skip to content

gh-132042: Try to optimize class creation #132156

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Include/cpython/descrobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct wrapperbase {
const char *doc;
int flags;
PyObject *name_strobj;
uint8_t name_count;
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment explaining the purpose of this member and how it's computed. You can mention _PyType_InitSlotDefsNameCounts().

};

/* Flags for above struct */
Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,6 @@ struct _Py_interp_cached_objects {

/* object.__reduce__ */
PyObject *objreduce;
PyObject *type_slots_pname;
pytype_slotdef *type_slots_ptrs[MAX_EQUIV];

/* TypeVar and related types */
PyTypeObject *generic_type;
Expand Down
3 changes: 3 additions & 0 deletions Include/internal/pycore_typeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ typedef int (*_py_validate_type)(PyTypeObject *);
extern int _PyType_Validate(PyTypeObject *ty, _py_validate_type validate, unsigned int *tp_version);
extern int _PyType_CacheGetItemForSpecialization(PyHeapTypeObject *ht, PyObject *descriptor, uint32_t tp_version);

// Precalculates count of non-unique slots
extern int _PyType_InitSlotDefsNameCounts(PyInterpreterState *interp);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve class creation times by up to 40%. Patch by Sergey Miryanov.
Loading
Loading