Repository navigation
Add a diagnostic mode for ArrayPool.Shared - #109695
stephentoub wants to merge 1 commit into
Conversation
bb6c32d to
cdc4872
Compare
| // Store the shared ArrayPool in a field of its derived sealed type so the Jit can "see" the exact type | ||
| // when the Shared property is inlined which will allow it to devirtualize calls made on it. | ||
| private static readonly SharedArrayPool<T> s_shared = new SharedArrayPool<T>(); | ||
| private static readonly ArrayPool<T> s_shared = SharedArrayPoolStatics.s_diagnosticPoolEnabled ? |
There was a problem hiding this comment.
The diagnostic pool in this PR is comparatively super expensive, but we could possibly have this turned on automatically when in debug / optimizations disabled, at least when running on coreclr.
There was a problem hiding this comment.
we could possibly have this turned on automatically when in debug / optimizations disabled
It is something to validate together with VS debugger. Similar super expensive debug-only aids did not fly well in the past. They degraded debugging experience too much.
|
Interesting idea! I presume it might miss cases when such arrays become immortal roots? (perhaps, a timer walking returned arrays in |
There are two things being checked currently:
The first would work regardless of whether the array is rooted forever. The second wouldn't work if the array is rooted forever as it's based on finalization and will only kick in after all references are dropped.
That's possible. Not sure it's worth it, but if others think the PR in general has merit, we could extend it in various ways. |
|
Would this find ArrayPool related bugs that got checked in into this repo? |
915862b to
44191ad
Compare
|
@stephentoub The implementation you have pretty much matches what was contemplated in one of the earlier security documents, with one exception: The security doc also contemplated something like what @EgorBo said, where the array pool always returns more bytes than specified, to help weed out the cases where people were relying on some implementation detail of it. Essentially: keep the power-of-two growth logic as-is, but put a |
+1. This would have caught #71696 |
|
Closing for now until we have time to gather sufficient evidence this would help. |
@jkotas, @GrabYourPitchforks, @EgorBo, opinions on whether this is worthwhile, and/or better approaches?