-
Notifications
You must be signed in to change notification settings - Fork 272
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
Refactor initialization logic to allow for enabling Memory Randomization #1587
Conversation
…otNet#1573 has solved the problem
…tion as it's usually the first thing called from GlobalSetup method which with MemoryRandomization enabled is the first method called right after allocation of random-sized memory by BDN engine
… that allocate less as Global Setup methods might get called right after random-size memory allocation
…ors (to allow for re-allocation with different alignment)
…mbining with existing one
…oryRandmization is enabled this is due to having new _arrayBufferWriter every time and allocating a lot of memory so we don't always allocate a new instance
This will be interesting to @kunalspathak |
# Conflicts: # src/harness/BenchmarkDotNet.Extensions/BenchmarkDotNet.Extensions.csproj
This reverts commit d02c372.
I've changed this PR to not enable the Memory Randomization, but just refactor the initialization logic to allow for enabling Memory Randomization in the near future. So this PR should have no effect on the reported time as of now. Memory Randomization will change the behavior of @DrewScoggins @kunalspathak please take a look. |
The CI failures are not related to microbenchmarks, so the PR should be ready to merge |
Thanks @adamsitnik for putting this together. Are we also doing anything to avoid allocating inside the benchmark method itself to reduce the effect of GC? Several array benchmarks allocate an array inside the benchmark method. |
@AndyAyersMS - FYI. |
I am working through this PR file by file. Should have comments later today. |
I skimmed through the PR and looks ok. I will let @DrewScoggins do the sign off. |
We recommend not to allocate any arrays in the new benchmarks (https://github.com/dotnet/performance/blob/master/docs/microbenchmark-design-guidelines.md#setup). When it comes to the old ones they were left mostly unchanged when I was porting them to BenchmarkDotNet. One of the requirements was to use the existing Reporting System (called BenchView back then). This has enforced the rule of not changing the IDs (type, method, and argument names), and not modifying the benchmarks (unless they had bugs) to not introduce any changes in the reported time (to keep the trends as they were). If these allocations are a problem, we should move them to setup methods. @kunalspathak would you like to send a PR based on your recent research? |
Absolutely. |
@DrewScoggins ping |
I just realized that there are certain benchmarks which allocates data to
Should this also need fixup? |
src/benchmarks/micro/libraries/System.Text.Json/Document/EnumerateArray.cs
Show resolved
Hide resolved
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.
LGTM
@kunalspathak @DrewScoggins thank you for your reviews! |
Edit: see #1587 (comment)
I am currently working on an experiment with Memory Randomization in BDN (dotnet/BenchmarkDotNet#1587)The goal is to find benchmarks that are heavily dependent on memory alignment and make it hard for us to reliably detect regressions, discuss the solution, and then apply it.Currently, I am opening this PR just so others can see the code changes that were needed to make it work and perhaps give it a try.Next, I am going to create an issue with my findings, we are going to discuss it and see what we do next.