C
C#3y ago
br4kejet

❔ Release mode garbage collection is much longer than debug mode

I built a WPF app, and to test the lag, i'm just selecting a ListBoxItem and moving my mouse up and down (which generates lots of garbage due to WPF). When i build my app in debug mode and run it in VS, the garbage collection is almost instant and there's practically no spikes or stoppages when constantly changing the selected item. But when i build it in release mode, every half a second there's a spike for about 600ms or so. What could be causing this? (I added a small progress bar to show the memory usage, and the usage drops after the large spikes in Release mode, but in debug mode it's like it just randomly drops)
16 Replies
mtreit
mtreit3y ago
600ms is insanely long for a GC, I'm skeptical that is actually a GC pause. You should take a performance profile.
br4kejet
br4kejetOP3y ago
The lag doesn't exist in the performance profiler, probably because it's running in debug mode 😦 In says the garbage collection is about 19ms, not sure about release mode though
mtreit
mtreit3y ago
Take an ETW trace of the release mode behavior.
br4kejet
br4kejetOP3y ago
Is that an external app or nuget library or something?
mtreit
mtreit3y ago
ETW is a technology in Windows for recording things like performance profiles. There are a variety of ways to take such traces (traditionally I have used the PerfView tool) but these days I find this tool the simplest to use to get an actual trace: https://github.com/google/UIforETW
GitHub
GitHub - google/UIforETW: User interface for recording and managing...
User interface for recording and managing ETW traces - GitHub - google/UIforETW: User interface for recording and managing ETW traces
mtreit
mtreit3y ago
Just unzip it and run. Then once you have a trace you can analyze it in something like Windows Performance Analyzer (warning: not very user friendly for beginners) or PerfView. Analyzing such traces is kind of an advanced skill but if you're able to do it you should be able to see where all of that time is being spent during those long pauses.
br4kejet
br4kejetOP3y ago
I'm 99% certain it's the garbage collector there's nothing else that could be causing such huge spikes in my code
mtreit
mtreit3y ago
A perf trace should show much time was spent in GC
br4kejet
br4kejetOP3y ago
Does c# does ahead of time compilation instead of JIT? suppose it could be the compiler maybe but i dunno why it would be halting the UI thread...
mtreit
mtreit3y ago
AOT is a feature you can opt-in to but out-of-the-box it uses JIT I found an email from Maoni (the dev who owns the GC) that suggests this for taking a perf trace that should show the GC stats:
PerfView /ThreadTime /Providers:ClrPrivate:1:5 /ClrEvents=default-GCHeapSurvivalAndMovement /StopOnGCOverMSec:1000 /DelayAfterTriggerSec:0 /CollectMultiple:3 /CircularMB:2000 /Merge:TRUE /Zip:TRUE /NoGUI collect
PerfView /ThreadTime /Providers:ClrPrivate:1:5 /ClrEvents=default-GCHeapSurvivalAndMovement /StopOnGCOverMSec:1000 /DelayAfterTriggerSec:0 /CollectMultiple:3 /CircularMB:2000 /Merge:TRUE /Zip:TRUE /NoGUI collect
br4kejet
br4kejetOP3y ago
couldn't figure out how to do that, but what's weird is if i build the app in Rider's release mode instead of VS release mode, i don't get those lag spikes actually it seems like the lag only happens when the app runs standalone instead of being attached to VS/Rider... pretty weird
mtreit
mtreit3y ago
I would definitely get a perf trace if possible. If you can create a small stand-alone repro that would also help, since the behavior you are describing definitely should not happen. So this could result in a github issue if there is an actual problem with the .net runtime.
br4kejet
br4kejetOP3y ago
I have the app on github if you want to try it out for yourself. I might just try and figure out how to disable WPF's auto scrolling while moving the mouse
br4kejet
br4kejetOP3y ago
GitHub
GitHub - AngryCarrot789/BCEdit180: A java class file viewer and edi...
A java class file viewer and editor, written in C#. Similar to jclasslib but supports extra features such as copy and paste bytecode between methods - GitHub - AngryCarrot789/BCEdit180: A java clas...
WhiteBlackGoose
did you tweak GC? although I'd follow mtreit's advice
Accord
Accord3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server