[ https://issues.apache.org/jira/browse/ARROW-2354?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16414170#comment-16414170 ]
ASF GitHub Bot commented on ARROW-2354: --------------------------------------- pitrou commented on a change in pull request #1794: ARROW-2354: [C++] Make PyDecimal_Check() faster URL: https://github.com/apache/arrow/pull/1794#discussion_r177169733 ########## File path: cpp/src/arrow/python/helpers.cc ########## @@ -227,12 +227,16 @@ Status UInt64FromPythonInt(PyObject* obj, uint64_t* out) { } bool PyDecimal_Check(PyObject* obj) { - // TODO(phillipc): Is this expensive? - OwnedRef Decimal; - Status status = ImportDecimalType(&Decimal); - DCHECK_OK(status); - const int32_t result = PyObject_IsInstance(obj, Decimal.obj()); - DCHECK_NE(result, -1) << " error during PyObject_IsInstance check"; + static OwnedRef decimal_type; Review comment: Here is an alternative implementation. Which one do you prefer? ```c++ bool PyDecimal_Check(PyObject* obj) { OwnedRef decimal_type; PyTypeObject* obj_type = Py_TYPE(obj); // Fast fail for most types other than Decimal, for speed if (strcmp(obj_type->tp_name, "decimal.Decimal")) { return false; } Status status = ImportDecimalType(&decimal_type); DCHECK_OK(status); DCHECK(PyType_Check(decimal_type.obj())); // PyObject_IsInstance() is slower as it has to check for virtual subclasses const int result = PyType_IsSubtype(obj_type, reinterpret_cast<PyTypeObject*>(decimal_type.obj())); DCHECK_NE(result, -1) << " error during PyType_IsSubtype check"; return result == 1; } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > [C++] PyDecimal_Check() is much too slow > ---------------------------------------- > > Key: ARROW-2354 > URL: https://issues.apache.org/jira/browse/ARROW-2354 > Project: Apache Arrow > Issue Type: Bug > Components: C++, Python > Affects Versions: 0.9.0 > Reporter: Antoine Pitrou > Assignee: Antoine Pitrou > Priority: Major > Labels: pull-request-available > > See https://github.com/apache/arrow/issues/1792 -- This message was sent by Atlassian JIRA (v7.6.3#76005)