-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Defer resolution of StackTrace debug info until use #115019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreCLR.cs
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreCLR.cs
Outdated
Show resolved
Hide resolved
@@ -86,8 +86,40 @@ public StackFrameHelper() | |||
internal void InitializeSourceInfo(bool fNeedFileInfo, Exception? exception) | |||
{ | |||
StackTrace.GetStackFramesInternal(this, fNeedFileInfo, exception); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to also defer Windows PDB data resolution, but that requires some nontrivial changes in the runtime.
Hi @nike4613! Thank you for the community PR! I believe there is at least one comment that should be addressed to help move this PR forward. Do you plan on working on it in the near term? If not, would you be interested in moving this PR to Draft? |
@tommcdon Yes, I should have some stuff today even. |
c593348
to
f23f1fe
Compare
vzeroupper is AVX instruction and so it cannot be executed unconditionally in static asm helpers Fixes dotnet#115019
vzeroupper is AVX instruction and so it cannot be executed unconditionally in static asm helpers Fixes dotnet#115019
…e the actual StackFrameHelper frame count
The remaining test failures appear to be unrelated to this PR; at least the OSX failure seems spurious. Not sure about the WASM failure. |
src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreCLR.cs
Outdated
Show resolved
Hide resolved
|
||
private StackFrame[] GetFramesCore() | ||
{ | ||
return _stackFrames ?? []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should NativeAOT get the same optimization? We do not want NativeAOT performance to be lagging behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if debug info resolution is as significant on NAOT; I haven't benched it. My driving scenario is JIT-only for entirely separate reasons anyway. It shouldn't be too hard to do there, though I'd want to profile it first.
What needs to happen to push this forward? |
rgiILOffset![index], out rgFilename![index], out rgiLineNumber![index], out rgiColumnNumber![index]); | ||
|
||
// Make sure we mark down that debug information for this frame was resolved | ||
rgiMethodToken[index] = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be thread safe? Other parts of the change use Interlocked.CompareExchange that suggests this is expected to be thread safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely. I think it should be sufficient to outline the out
parameters to be assigned after the call returns, and make the read/write to rgiMethodToken[index]
volatile? The data race will only see multiple threads executing here, and both should result in the same values, so I don't think anything more is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, something like this should work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be done now
In profiling an application I work on, I've found that a significant amount of time is spent capturing stack traces. The usage of these stack traces is somewhat unusual, however, in that I do not know whether any given trace is needed until much later, at which point, if I do need it, I want debug information.
Profiling this, I've found that with portable debug info, nearly half of the time spent capturing a stack trace is in fact spend resolving debug info (and more with Windows
full
PDBs). For my usecase, deferring that resolution until use-site can significantly improve capture performance, without loosing access to debug info.Comparison benchmarks
With this PR, capturing a trace with
fNeedFileInfo: true
is only slightly slower than capturing without, and the cost involved in resolving debug info is deferred until enumeration.This PR in its current state is minimally invasive; there are several places I have not yet touched so that I could demonstrate the above difference.
Benchmark files
stacktrace-perf.csproj
Program.cs
Benchmarks.cs