Slow `frame` functions
Hello! I use boost stacktrace library and frame functions like name() are taking too much time (like +-10seconds) probably because of the large binary (about 35MB). Is there any way I can speed up these functions?
SetUp Compiler: clang-18 Flags: -DBOOST_STACKTRACE_USE_BACKTRACE -DBOOST_STACKTRACE_LINK
What flag do you use for compiling your application? Are you using SSD? What operating system do you use?
Thank you @apolukhin for such a quick response! Flags: -fno-pie -fvisibility-inlines-hidden -O3 -funroll-loops -fno-omit-frame-pointer -flto=thin -DNDEBUG -DBOOST_STACKTRACE_USE_BACKTRACE -DBOOST_STACKTRACE_LINK SSD is not used OS is Ubuntu20
@HazyMrf 35mb does seem to be big enough to drastically slow down the name() function.
My guesses are:
0. Try preload all the internal staff by calling to_string(boost::stacktrace::stacktrace()). Does it help the subsequent calls?
- You are throwing exceptions or getting other stacktraces concurrently. Ubuntu20 has an old libc that locks+unlocks mutex on each frame unwinding. As a result multiple concurrent exceptions|backtraces could degrade performance to multiple seconds per one function call. The most simple solution - is to migrate to a new distro.
- Try defining BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC while compiling the boost.stacktrace library. Does it help?
Nope, any of the things you suggested didn't help :( Well I'll continue to use address() because it is extremely cheap. I've always thought that addr2line is slow and when using backtrace / libbacktrace I'll get super-performance, but I was mistaken...
Can not reproduce the problem. Works fine with Ubuntu 20.04- Ubuntu 24.04 on a multi-gigabyte binariees, tested on https://github.com/userver-framework/userver/ project, on hundreds of services