[ 
https://issues.apache.org/jira/browse/ARROW-2400?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16426848#comment-16426848
 ] 

Antoine Pitrou commented on ARROW-2400:
---------------------------------------

This patch seems to improve things by ~15% here on gcc 4.9:

{code:c++}
diff --git a/cpp/src/arrow/status.h b/cpp/src/arrow/status.h
index 84f55e4..a2cf438 100644
--- a/cpp/src/arrow/status.h
+++ b/cpp/src/arrow/status.h
@@ -107,7 +107,11 @@ class ARROW_EXPORT Status {
  public:
   // Create a success status.
   Status() : state_(NULL) {}
-  ~Status() { delete state_; }
+  ~Status() {
+    if (ARROW_PREDICT_FALSE(state_ != NULL)) {
+      DeleteState();
+    }
+  }
 
   Status(StatusCode code, const std::string& msg);
 
@@ -207,6 +211,10 @@ class ARROW_EXPORT Status {
   // a `State` structure containing the error code and message(s)
   State* state_;
 
+  void DeleteState() {
+    delete state_;
+    state_ = NULL;
+  }
   void CopyFrom(const State* s);
 };
 {code}

> [C++] Status destructor is expensive
> ------------------------------------
>
>                 Key: ARROW-2400
>                 URL: https://issues.apache.org/jira/browse/ARROW-2400
>             Project: Apache Arrow
>          Issue Type: Improvement
>    Affects Versions: 0.9.0
>            Reporter: Antoine Pitrou
>            Priority: Major
>
> Let's take the following micro-benchmark (in Python):
> {code:bash}
> $ python -m timeit -s "import pyarrow as pa; data = [b'xx' for i in 
> range(10000)]" "pa.array(data, type=pa.binary())"
> 1000 loops, best of 3: 784 usec per loop
> {code}
> If I replace the Status destructor with a no-op:
> {code:c++}
>   ~Status() { }
> {code}
> then the benchmark result becomes:
> {code:bash}
> $ python -m timeit -s "import pyarrow as pa; data = [b'xx' for i in 
> range(10000)]" "pa.array(data, type=pa.binary())"
> 1000 loops, best of 3: 561 usec per loop
> {code}
> This is almost a 30% win. I get similar results on the conversion benchmarks 
> in the benchmark suite.
> I'm unsure about the explanation. In the common case, {{delete _state}} 
> should be extremely fast, since the state is NULL. Yet, it seems it adds 
> significant overhead. Perhaps because of exception handling?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to