[
https://issues.apache.org/jira/browse/ARROW-12533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17332889#comment-17332889
]
Yibo Cai edited comment on ARROW-12533 at 4/27/21, 4:20 AM:
------------------------------------------------------------
This issue is gone if using clang's own c++ library libc++.
Most Linux distros only installs gnu libstdc++. Clang libc++ is not widely
used. I tested clang libc++ on ubuntu-18.04 aarch64. The test binary is 100x
faster with clang libc++ than gnu libstdc++.
See https://godbolt.org/z/d79TW53cb, adding '-stdlib=libc++' generates much
better code.
{code:bash}
$ sudo apt install libc++-dev libc++abi-dev
# test gnu libstdc++
$ clang++-10 -O3 test.cc
$ time ./a.out
real 0m11.002s
user 0m10.998s
sys 0m0.004s
# test clang libc++
$ clang++-10 -stdlib=libc++ -O3 test.cc
$ time ./a.out
real 0m0.099s
user 0m0.095s
sys 0m0.004s
{code}
was (Author: yibocai):
This issue is gone if using clang's own c++ library libc++.
Most Linux distros only installs gnu libstdc++. Clang libc++ is not widely
used. I tested clang libc++ on ubuntu-18.04 aarch64. The test binary is 100x
faster with clang libc++ than gnu libstdc++.
{code:bash}
$ sudo apt install libc++-dev libc++abi-dev
# test gnu libstdc++
$ clang++-10 -O3 test.cc
$ time ./a.out
real 0m11.002s
user 0m10.998s
sys 0m0.004s
# test clang libc++
$ clang++-10 -stdlib=libc++ -O3 test.cc
$ time ./a.out
real 0m0.099s
user 0m0.095s
sys 0m0.004s
{code}
> [C++] Random real generator is slow on Arm64 Linux when built with clang
> ------------------------------------------------------------------------
>
> Key: ARROW-12533
> URL: https://issues.apache.org/jira/browse/ARROW-12533
> Project: Apache Arrow
> Issue Type: Improvement
> Components: C++
> Reporter: Yibo Cai
> Priority: Minor
>
> Many benchmarks run very slow on Arm64 Linux when built with clang.
> Most time is spent in preparing test data, not the test itself.
> Per my investigation, it boils down to poor performance of
> `std::uniform_real_distribution`, which uses software emulated `long double`
> arithmetic on Arm64 [1].
> Apple M1 doesn't have this issue. Clang aarch64 sets `long double` size to 64
> bits on MacOS, but 128 on Linux [2].
> Gcc aarch64 doesn't have this issue. It doesn't use `long double` to generate
> random reals [1]. Guess clang uses algorithms with better randomness.
> clang `-ffast-math` option removes the `long double` arithmetic (and adds
> other simplifications to floating point arithmetic), it improves speed 100x
> on Arm64 in generating random reals.
> It may deserve some effort to study if `long double` is really necessary, and
> if `-ffast-math` is acceptable for generating test bits.
> [1] [https://godbolt.org/z/Y3Tc6MTME]
> [2] [https://en.wikipedia.org/wiki/Long_double]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)