bombela / backward-cpp

A beautiful stack trace pretty printer for C++
MIT License
3.66k stars 466 forks source link

Slow stacktraces in large projects #323

Open diehard2 opened 6 months ago

diehard2 commented 6 months ago

Hi, really like this library a lot. I'm working off the latest commit. My project is fairly large although not excessive, the executable is 127 MB.

For BFD I'm seeing it take approximately 2.3 seconds to generate the stacktraces (no source printing). If I use dw I'm seeing 860 ms. It does not get faster on subsequent runs. For reference, an approach I have that calls out to addr2line takes about 500ms for the same stack.

If I use boost stacktrace (which I do not like as much) and use libbacktrace I am seeing 192 ms for the first call and sub ms for subsequent calls due to their caching.

Is there anything that can be done here? If it helps this is the flamegraph for bfd. The reason I am looking for performant stacktraces is I'm logging them whenever there is a failure in my service and processing then continues. Thanks for any help

image

bombela commented 6 months ago

Your executable is 4x bigger than the RAM on my first computer xD

I am afraid you reached the limits here. It should be possible to add libbacktrace support to backward-cpp. Similar to how it handles dw and bfd.

Feel free to give it a go. Add a new define atop of backward.hpp. Add the ifdef to include the libbacktrace header. Then follow the example of bfd and dw to implement the resolver class within ifdefs :)

Or maybe your solution is best solved by using libbacktrace directly. Afterall it can do what backward-cpp does, but faster. You would only need to implement a trace formatter. Feel free to copy or getting inspiration from the formatting code in backward-cpp.

On Fri, Dec 15, 2023, 00:15 diehard2 @.***> wrote:

Hi, really like this library a lot. I'm working off the latest commit. My project is fairly large although not excessive, the executable is 127 MB.

For BFD I'm seeing it take approximately 2.3 seconds to generate the stacktraces (no source printing). If I use dw I'm seeing 860 ms. It does not get faster on subsequent runs. For reference, an approach I have that calls out to addr2line takes about 500ms for the same stack.

If I use boost stacktrace (which I do not like as much) and use libbacktrace I am seeing 192 ms for the first call and sub ms for subsequent calls due to their caching.

Is there anything that can be done here? If it helps this is the flamegraph for bfd. The reason I am looking for performant stacktraces is I'm logging them whenever there is a failure in my service and processing then continues. Thanks for any help

image.png (view on web) https://github.com/bombela/backward-cpp/assets/542044/283dff9e-74ad-4b4e-9edd-4b44e2684a37

— Reply to this email directly, view it on GitHub https://github.com/bombela/backward-cpp/issues/323, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABUZDH4YJXRYXJHIARGRWLYJOB7TAVCNFSM6AAAAABAVTL4KCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA2DENRUGQYDKOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>