-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Improve memory diagnoser accuracy #2562
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
Conversation
d351f0e
to
c864594
Compare
It looks like I may have resolved the zero-alloc issue! New results (using the same benchmark from #1543):
The resolution ended up being moving the I was unable to repro the issue in a plain console application, so I'm not sure why PTAL @adamsitnik |
3518d50
to
ce134ab
Compare
I added the thread sleep from #1543 in Core runtimes 3.0 to 6.0, and now I'm getting 0 measurements across the board:
|
0624a8c
to
917988c
Compare
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.
Big thanks for working on improving the accuracy of the memory diagnoser @timcassell !
Let's wait for the response from @Maoni0.
c192cb5
to
07d4c4c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Update: I found the culprit and opened an issue in dotnet/runtime. dotnet/runtime#101536 |
4d86cd1
to
31f280d
Compare
I disabled the flaky tests and left a todo to re-enable them when that issue is fixed. This is as accurate as we can make the memory diagnoser from our side. I think this should be good to merge now, unless you have any further feedback @adamsitnik. |
060ce34
to
63b62a9
Compare
Ok, I re-enabled the tests and added a finalizer thread blocker to make the tests less flaky (nice idea @jkotas). This does not have any effect on real world measurements, though. |
2548395
to
f6a4194
Compare
Wow, even with tiered jit disabled and finalizer thread blocked, the CI is still flaky. 2024-04-28T00:50:55.0136465Z Failed AllocationQuantumIsNotAnIssueForNetCore21Plus(toolchain: .NET 8.0) [9 s]
2024-04-28T00:50:55.0137358Z Error Message:
2024-04-28T00:50:55.0137773Z Assert.Equal() Failure: Values differ
2024-04-28T00:50:55.0138293Z Expected: 88
2024-04-28T00:50:55.0138634Z Actual: 176 I don't know what causes that behavior, but I just moved the MemoryDiagnoserTests to ManualRunning to stabilize the CI. |
My guess is that the next problem are the event source background threads. |
Can you provide more details? I couldn't find information about it from google. |
EventSource and EventPipe create background threads that may allocate. These background threads should be only doing work if there is something listening to the events. It turns out that there is pretty much always something listening to .NET runtime events in typical machine configs these days. |
You mentioned disabling that in the other issue. How can we do that? |
@adamsitnik Do you have any more feedback here? |
9e042a3
to
8162a98
Compare
8162a98
to
1797d9c
Compare
It seems the MemoryDiagnoser is returning obviously strange values. |
e7b29f3
to
1cb72cf
Compare
Fixed the last remaining flaky test allocation in the last commit. @adamsitnik PTAL |
2548037
to
37e0773
Compare
@AndreyAkinshin Can you review this if Adam is too busy? |
37e0773
to
c42ac99
Compare
…cations. Warm up allocation measurement before taking actual measurement. Isolated allocation measurement. Changed some `RuntimeInformation` properties to static readonly fields. Removed enable monitoring in Engine (GcStats handles it). Removed `GC.Collect()` from allocation measurement. Sleep thread to account for tiered jit in Core runtimes 3.0 to 6.0. Updated MemoryDiagnoserTests. Block finalizer thread during memory tests. Disabled EventSource for integration tests.
c42ac99
to
7e07056
Compare
Merging this. If you have any feedback, I can address it as follow-up @adamsitnik @AndreyAkinshin. |
Thank you @timcassell Before: https://github.com/Cysharp/ZLinq/actions/runs/15248058870 |
Awesome! It's nice to see improvements in real-world benchmarks.
Which benchmark do you expect to be zero that's not? I did see you are using ShortRun job settings. Do note that we cannot guarantee allocation results for methods that are not tier 1 jitted. JIT is free to insert allocations in tier 0 methods that's impossible for user code to do anything about. If you need the most accurate tier 1 measurements, mitigation options are to ensure the benchmark method is invoked at least 60 times (undocumented number that may change at any point), or disable tiered jit. |
Count00 shows 2B.
Thank you for the additional detailed information, it's very helpful! |
This doesn't fix the zero-alloc measurement, but it does fix a bug from the threading diagnoser interfering with the results. The other changes give us the highest confidence that any errant measurements are not our fault. The rest is up to the runtime.Fixes #1542