You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of our usages of getStackTrace() are from reporting the stack trace of an already thrown exception. However, the StackOverflow post linked above indicates that StackWalker can't be used to process the stack trace of an already thrown exception, so DriverStation.reportError() and MathSharedStore.reportError() have to keep the StackTraceElement[] parameter for that use case. We could make DriverStation.reportError(String error, boolean printTrace) overload use StackWalker, but that would lead to code duplication since we still need the logic for the StackTraceElement[] case.
This isn't the main point of this issue, but the efficiency seems to be from not having to create all of the stack trace elements, but because our usages of the stack traces are reporting errors, we have to process all of the stack trace elements anyways. (The only elements we skip are from the top of the stack, which means that the walker still has to create all of the elements for us to either determine we should skip or to report in the (processed) stack trace)
Summary: We could use StackWalker for DriverStation.reportError(String error, boolean printTrace), but that would lead to code duplication. If we want to use the stream API for more ergonomic processing, we could stream the array of stack trace elements (though that would add the stream API's overhead).
Apparently Java has a stackwalking API: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/StackWalker.html
We currently do the logic inline (for example, in the scheduler code) via an
Exception.getStackTrace()
.This API is more ergonomic and is supposedly more efficient.
The text was updated successfully, but these errors were encountered: