Backtraces taking too long in server applications

I thought it worth posting to highlight a change in Swift 5.10 that will be beneficial to anyone who has been finding that crashes in their Swift programs take too long to generate a backtrace (this is mainly a problem for server-side programs, where you'd ideally like the program to crash quickly so something can restart it, but you'd still like an actionable backtrace).

Specifically, we've added an new option to the SWIFT_BACKTRACE environment variable that lets you control symbolication (which is the part of the process that is taking the time); if you set

SWIFT_BACKTRACE=symbolicate=fast

then the backtracer will look up symbols, but will not try to give line number information or decode inline frames. This should speed things up significantly in most cases.

If that is still a problem for your application, please do file an Issue about it, but you can also completely disable symbolication with

SWIFT_BACKTRACE=symbolicate=off

You'll still get a backtrace, but in the latter case it'll just have addresses. It does list the loaded images, so you should be able to work backwards from that information later on if you need to.

(I am looking into the amount of time it takes to do the full symbolication in these cases; hopefully at some point there will be some additional improvements there too.)

See also the backtracing documentation in the Swift repo.

15 Likes

So it won't mention the line number info basically all the time?
It will still include the function and file names?
Trying to have a better understanding before actually using it in a project and see how it goes IRL.

Yes, that's correct, it won't mention the line number, but it will still include function names (and offsets within the function).

2 Likes