stacktrace icon indicating copy to clipboard operation
stacktrace copied to clipboard

Slow `frame` functions

Open HazyMrf opened this issue 1 year ago • 4 comments

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

HazyMrf avatar Oct 24 '24 17:10 HazyMrf

What flag do you use for compiling your application? Are you using SSD? What operating system do you use?

apolukhin avatar Oct 26 '24 10:10 apolukhin

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 avatar Oct 30 '24 11:10 HazyMrf

@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?

  1. 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.
  2. Try defining BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC while compiling the boost.stacktrace library. Does it help?

apolukhin avatar Dec 22 '24 13:12 apolukhin

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...

HazyMrf avatar Jan 09 '25 10:01 HazyMrf

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

apolukhin avatar Nov 08 '25 11:11 apolukhin