5 ms·
you only do it when there is a not nil err + being able to have a stacktrace is worth more than whatever it costs is CPU
by tbarbugli 3y ago
you only do it when there is a not nil err + being able to have a stacktrace is worth more than whatever it costs is CPU
- Cthulhu_ 3y agoThat's still under the assumption that errors are exceptional, rare, and require a stacktrace to debug. But most errors are not exceptional and do not need debugging, like idk, a row not found error in a database. A crash, sure, that might need a stacktrace to debug. But that's already in place.
- kbolino 3y agoGood error-wrapping discipline works better than stack traces, because not only do you have a trace of the calling context, you also have the values that caused the problem. Granted, a stack trace "always works", but it will never have the values of important variables.
- Cthulhu_ 3y agoNow you mention it, a stack trace with function calls and all their arguments would be really powerful. But also expensive, ideally it would have zero overhead or only have the cost if you actually look at it / want to debug it.
- kbolino 3y agoOne of the major optimizations is to pass function arguments in registers instead of on the stack. These registers might preserve their original values by the time you unwind the stack, but in many cases, probably won't. Preserving those values would lead to fewer available registers and/or more frequent register saving, which would create at least some overhead, even if you don't ever inspect it. There are probably lots of situations where it's worth it, though.
- derekperkins 3y agoWe do both and it works great