This is an automated email from the ASF dual-hosted git repository.
yibocai 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 56cdaae781 MINOR: [C++] Move static declaration to non-static
declaration to improve performance (#13222)
56cdaae781 is described below
commit 56cdaae781ba792df8b085ff4022796344b06e3b
Author: Weston Pace <[email protected]>
AuthorDate: Mon May 30 15:25:42 2022 -1000
MINOR: [C++] Move static declaration to non-static declaration to improve
performance (#13222)
According to conbench there was a slight regression on #12957 . Poking
around a bit it seems that a static local variable is implemented using some
kind of global lock (__cxa_guard_acquire / __cxa_guard_release). On the other
hand, constructing an empty shared_ptr is cheap (two pointers are set to 0).
So if we care about performance here we probably don't want `static`. This may
be what is causing the conbench issue.
Lead-authored-by: Weston Pace <[email protected]>
Co-authored-by: Antoine Pitrou <[email protected]>
Signed-off-by: Yibo Cai <[email protected]>
---
cpp/src/arrow/compute/exec/expression.cc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/cpp/src/arrow/compute/exec/expression.cc
b/cpp/src/arrow/compute/exec/expression.cc
index e23bd0683a..a65379460d 100644
--- a/cpp/src/arrow/compute/exec/expression.cc
+++ b/cpp/src/arrow/compute/exec/expression.cc
@@ -107,9 +107,12 @@ ValueDescr Expression::descr() const {
return CallNotNull(*this)->descr;
}
+// This is a module-global singleton to avoid synchronization costs of a
+// function-static singleton.
+static const std::shared_ptr<DataType> kNoType;
+
const std::shared_ptr<DataType>& Expression::type() const {
- static const std::shared_ptr<DataType> no_type;
- if (impl_ == nullptr) return no_type;
+ if (impl_ == nullptr) return kNoType;
if (auto lit = literal()) {
return lit->type();