I’m searching for a performance problem in a Windows WPF C++/C# 64-bit app. When run under the debugger (which includes running with the debug heap), the app is sometimes very slow, taking several seconds to respond to each click. During the slow period, the MSVS profiler reports UMThunkStubAMD64 as the function doing the most work (25% exclusive samples). The name sounds like it’s some kind of adapter/wrapper function, maybe for calling 32-bit OS code from 64-bit app code, but I’m wondering if it’s doing more work, like checking heap state.
What is UMThunkStubAMD64? Are there any factors that influence its performance?
UMThunkStubAMD64is a thunk that handles transitions from native to managed code.If 25% of samples are in this thunk, it is likely that the profiler is only profiling native code. If so, any samples taken when managed code is executing will show up in the bucket for the last native frame on the stack, which will be the native to managed thunk. The 25% would thus mean that (roughly) 25% of the run time is spent executing managed code.
The thunk itself should be very fast: transitioning between native and managed code is not free, but a program should also not spend 25% doing so. It might be possible to come up with a contrived example that spent enormous amounts of time transitioning, but I’d guess that it’s highly unlikely to encounter such a scenario in real code.