This is an automated email from the ASF dual-hosted git repository.
cpcloud pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new f9f8320 ARROW-2354: [C++] Make PyDecimal_Check() faster
f9f8320 is described below
commit f9f8320339692d4134d1ef42c32cb7c8d547593e
Author: Antoine Pitrou <[email protected]>
AuthorDate: Mon Mar 26 19:38:25 2018 -0400
ARROW-2354: [C++] Make PyDecimal_Check() faster
This basically keeps an eternal reference to the decimal type.
Before:
```
[100.00%] ··· Running
convert_pandas.PandasConversionsToArrow.time_from_series
ok
[100.00%] ····
========= ========== ============= ============== ===========
-- dtype
--------- ---------------------------------------------------
size int64 float64 float64_nans str
========= ========== ============= ============== ===========
10 420±1μs 426±1μs 421±0.3μs 450±0.6μs
1000000 6.92±1ms 14.1±0.02ms 15.5±0.04ms 1.66s
========= ========== ============= ============== ===========
```
After:
```
[100.00%] ··· Running
convert_pandas.PandasConversionsToArrow.time_from_series
ok
[100.00%] ····
========= =========== ============= ==============
===========
-- dtype
---------
----------------------------------------------------
size int64 float64 float64_nans str
========= =========== ============= ==============
===========
10 425±0.9μs 428±1μs 430±0.8μs 438±0.6μs
1000000 7.49±1ms 14.2±0.04ms 15.4±0.05ms 99.2±1ms
========= =========== ============= ==============
===========
```
Author: Antoine Pitrou <[email protected]>
Closes #1794 from pitrou/ARROW-2354-faster-decimal-check and squashes the
following commits:
3e22cfe3 <Antoine Pitrou> ARROW-2354: Make PyDecimal_Check() faster
---
cpp/src/arrow/python/helpers.cc | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/cpp/src/arrow/python/helpers.cc b/cpp/src/arrow/python/helpers.cc
index 5719af6..63fee54 100644
--- a/cpp/src/arrow/python/helpers.cc
+++ b/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;
+ if (!decimal_type.obj()) {
+ 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(Py_TYPE(obj),
reinterpret_cast<PyTypeObject*>(decimal_type.obj()));
+ DCHECK_NE(result, -1) << " error during PyType_IsSubtype check";
return result == 1;
}
--
To stop receiving notification emails like this one, please contact
[email protected].