-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add generalized "mutating" blackHole
#323
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #323 +/- ##
==========================================
- Coverage 69.48% 69.46% -0.02%
==========================================
Files 33 33
Lines 3938 3939 +1
==========================================
Hits 2736 2736
- Misses 1202 1203 +1
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
I think this is a great addition, very happy to take it, thanks! WDYT choosing something like |
|
Probably should add a sample of using this / not using this into the test benchmarks embedded in the project, to highlight the importance and differences it makes? |
Makes sense. I'll do that along with example usage this week. |
Description
This PR adds another optimization blocker function to
Blackhole.swift. It could be thought of as the analogue of Google benchmark'sbenchmark::DoNotOptimize.This forces the compiler to assume that the passed argument is mutated in addition to just read. Consequently it can be used to block optimizations like loop-invariant code motion (LICM) that could happen when using an amortizing inner loop using
benchmark.scaledIterations. An example is provided in the doc comment.We had to implement this for some of our benchmarks, and it could potentially be useful for other users of package-benchmark as well.
It would be convenient to have it in package-benchmark as it appears that
@_optimize(none)is expected to work only if it's used in a different module.How Has This Been Tested?
I could use some guidelines on how to add a test for something like this.
It has not been "unit-tested" per se, but we have been using it in our benchmarks as mentioned above. The compiler was able to completely const-fold some of those loops without the
clobber(this PR'sblackHoleMutating).There are some disabled tests in AdditionalTests.swift that include a test for
blackHole. Perhaps a test could be added over there if those tests are enabled again. It appears that the tests could be enabled now as the issue mentioned therein (#178) is closed as completed now?Minimal checklist:
DocCcode-level documentation for any public interfaces exported by the package