-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
As we learned in PYTHON-3717 and PYTHON-3729, caching commonly used strings the C extensions can yield a big performance improvements. Let's cache the strings used in other places:
$ git grep 'String(' ... bson/_cbsonmodule.c:1540: PyObject* _id = PyDict_GetItemString(dict, "_id"); bson/_cbsonmodule.c:1547: } else if (PyMapping_HasKeyString(dict, "_id")) { bson/_cbsonmodule.c:1548: PyObject* _id = PyMapping_GetItemString(dict, "_id"); bson/_cbsonmodule.c:1623: raw_bson_document_bytes_obj = PyObject_GetAttrString(dict, "raw"); bson/_cbsonmodule.c:1664: if (PyMapping_HasKeyString(value, "$ref") && PyMapping_HasKeyString(value, "$id")) { /* DBRef */ bson/_cbsonmodule.c:1665: ref = PyMapping_GetItemString(value, "$ref"); bson/_cbsonmodule.c:1670: id = PyMapping_GetItemString(value, "$id"); bson/_cbsonmodule.c:1676: if (PyMapping_HasKeyString(value, "$db")) { bson/_cbsonmodule.c:1677: database = PyMapping_GetItemString(value, "$db"); bson/_cbsonmodule.c:1693: PyMapping_DelItemString(value, "$ref"); bson/_cbsonmodule.c:1694: PyMapping_DelItemString(value, "$id"); bson/_cbsonmodule.c:1696: PyMapping_DelItemString(value, "$db"); bson/_cbsonmodule.c:2105: replace = PyObject_GetAttrString(naive, "replace"); bson/_cbsonmodule.c:2122: if (!utc_type || PyDict_SetItemString(kwargs, "tzinfo", utc_type) == -1) { bson/_cbsonmodule.c:2140: astimezone = PyObject_GetAttrString(value, "astimezone");
PyDict_GetItemString can be replaced with PyDict_GetItem, PyMapping_DelItemString with PyMapping_DelItem, etc...
- is related to
-
PYTHON-3816 Use PyObject_GetItem instead of PyMapping_GetItemString
- Closed
- related to
-
PYTHON-3729 Speed up C BSON encoding by using PyObject_GetAttr instead of PyObject_GetAttrString
- Closed
-
PYTHON-3717 Speed up _type_marker check in BSON
- Closed