You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds another optimization blocker function to Blackhole.swift. It could be thought of as the analogue of Google benchmark's benchmark::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.
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's blackHoleMutating).
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:
I have performed a self-review of my own code
I have added DocC code-level documentation for any public interfaces exported by the package
I have added unit and/or integration tests that prove my fix is effective or that my feature works
❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.46%. Comparing base (3db567f) to head (bd5f48a). ⚠️ Report is 10 commits behind head on main.
I think this is a great addition, very happy to take it, thanks! WDYT choosing something like blackHoleMutating instead of clobber (which I personally feels is the naming of a function that truly would clobber/overwrite stuff, not just "fake it").
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?
I think this is a great addition, very happy to take it, thanks! WDYT choosing something like blackHoleMutating instead of clobber (which I personally feels is the naming of a function that truly would clobber/overwrite stuff, not just "fake it").
Makes sense. I'll do that along with example usage this week.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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