Repository navigation
Avoid boxing variables captured by closures - #1026
Merged
Merged
Conversation
Splitting `synchronize` into two `@autoreleasepool` blocks (#995, #1001) made their closures capture `queue` and `submissions`, which were later reassigned. That boxed both, making the rest of the function type unstable, and raised the latency of an empty `synchronize` from ~310 to ~600 ns. Stop rebinding them, and release the pool from a function that takes concrete arguments, which brings it back to ~480 ns with 2 instead of 5 allocations.
Reassigning a variable that a closure captures boxes it. With `@autoreleasepool function` wrapping the function body in a closure, this happened to arguments that were rebound after validation, and to the byte count `encode_copy!` decremented while copying. Test for this using `Test.detect_closure_boxes`, where available.
Contributor
Metal.jl BenchmarksDetails
This comment was automatically generated by workflow using github-action-benchmark. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1026 +/- ##
==========================================
+ Coverage 86.75% 86.77% +0.01%
==========================================
Files 89 89
Lines 6403 6403
==========================================
+ Hits 5555 5556 +1
+ Misses 848 847 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
metal/synchronization/streambenchmark (an emptysynchronize()) regressed from ~340 to ~640 ns over #995 and the #1001/#1002/#822 stack. Part of that is inherent to the extra locking those PRs need, but part comes from closure boxes: splittingsynchronizeinto two@autoreleasepoolblocks made their closures capturequeueandsubmissions, which were reassigned afterwards. Both got boxed, which made the rest of the function type unstable.Julia 1.14's
Test.detect_closure_boxesfound 9 more of these, mostly in@autoreleasepool functions rebinding an argument (that macro wraps the function body in a closure), includingencode_copy!on thecopyto!path. This PR removes all of them without introducing temporaries, and adds a test that runsdetect_closure_boxeson Julia versions that have it.Empty
synchronize()on an M1, Julia 1.12, three interleaved runs: