C
C#2y 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
mtreit2y ago
600ms is insanely long for a GC, I'm skeptical that is actually a GC pause. You should take a performance profile.
br4kejet
br4kejet2y 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
mtreit2y ago
Take an ETW trace of the release mode behavior.
br4kejet
br4kejet2y ago
Is that an external app or nuget library or something?
mtreit
mtreit2y 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
mtreit2y 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
br4kejet2y 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
mtreit2y ago
A perf trace should show much time was spent in GC
br4kejet
br4kejet2y 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
mtreit2y 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
br4kejet2y 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
mtreit2y 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
br4kejet2y 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
br4kejet2y 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
Accord2y 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
More Posts
❔ Getting the cookies and current Url from Webview [MAUI]I'm making a simple app where the user needs to log in the first time they're using it in WebView anWhat is the difference between these two methods? Using params or just doing everything in one class```cs public static void Main(string[] args) { int a = 2, b = 3; int sum = Add(a, b) } public s❔ How do I pull information out of a function with alot of information?**I'm getting an error in the below statement SPECIFICALLY at keySet with the error "the name 'keySe❔ Single UDP Broadcaster to Multiple ClientsI'm trying to have a single UDP Broadcast to many clients. This is what I have working so far. Idea❔ how to logout specific user with identityserverI am trying to logout an specific user from previous identity user sessions, so what could I do to ❔ The type 'Attribute' is defined in an assembly that is not referenced.On a dotnet 7 xunit template, I added specflow and the title error pops upHow do I create a class with an array within it?I'm trying to create a class for people with an array of hobbies within it, but cannot figure out ho❔ EF Core - Select items such that attribute sum is greater than...Hi everyone, I have an object Recording having attributes start_time and size_byte. Now, when the s❔ alternative to switch statement or if statements?is there something better I can use in this situation? ```cs int size = 300; switch (HLevel.CurrentL❔ deserialize json object which should be an arrayHi, how can i deserialize a json-string like this, if i dont know how many "items" (item0, item1, it