Fix data race in inference profiling (@snoopi_deep
).
#47258
Closed
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.
Previously, there wasn't a lock around
reset_timings()
, so if one thread resets the inference profile timings while another thread is in the middle of profiling type inference, this can crash type inference.There is still a logical race (the first thread's profile would be cleared by the second thread, and when the first thread finishes profiling, it would disable the inference timing for the second thread), but this fixes the data race.
Type inference is currently guarded by a global typeinf_lock, which the type inference profiler takes advantage of to protect data access safety. If we ever make the inference lock more granular, or make inference concurrent, we should add a separate lock around the inference profiles.
For more details on our plan to allow concurrent callers to
@snoopi_deep
, see: https://docs.google.com/document/d/1JO43w3V1Cwtb2CxWf4sYfAB68xbkTrCMr973iaJOFwY/edit#.This can mostly happen entirely in the SnoopCompile.jl package, but I wanted to come back here and close the loop on this, to tie up lose ends, in case anyone else encounters this. 😊
Before:
After 😊: