From 0c4e99b960e09e5bab3f897e8d8003daeb19d043 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Thu, 29 Oct 2026 17:41:06 +0100 Subject: [PATCH] Use the dict freelist in dict() dict_vectorcall() allocated every instance with _PyType_AllocNoTrack(), so dict() never reused the objects that {} and PyDict_New() recycle through the freelist. Allocate with PyDict_New() instead. tp_vectorcall is not inherited by subclasses, so dict_vectorcall() only ever runs for the exact dict type; assert that rather than checking it. Co-Authored-By: Claude Fable 5.1 --- Objects/dictobject.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 13c9e2e4b395abd..97fe9085ba08e02 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -5415,7 +5415,8 @@ dict_vectorcall(PyObject *type, PyObject * const*args, return NULL; } - PyObject *self = dict_new(_PyType_CAST(type), NULL, NULL); + assert(type == (PyObject *)&PyDict_Type); + PyObject *self = PyDict_New(); if (self == NULL) { return NULL; }