Uh oh!
There was an error while loading. Please reload this page.
lock protect nullability cache of symbolic regex node - #60942
Conversation
ghost
commented
Oct 27, 2021
Tagging subscribers to this area: @eerhardt, @dotnet/area-system-text-regularexpressions Issue DetailsAdded lock to protect
|
Uh oh!
There was an error while loading. Please reload this page.
d681d61 to
6e4e4d8Comparestephentoub
commented
Oct 28, 2021
@veanes, I tried running this with our perf tests in dotnet/performance, just with NonBacktracking subbed in for the options. There are a few notable regressions. Is that expected?
|
veanes
commented
Oct 28, 2021
I would not expect any noticeable regressions, because I was expecting the change (locking) not to really affect the hot-path. If I understand correctly, 22% slower for example for |
stephentoub
commented
Oct 28, 2021
veanes
commented
Oct 28, 2021
OK, indeed they do indeed use |
Alternative would be to use a nested array nullability[][] of size 5x5 in each node. is thread-safe without any locks. I believe that would be the more efficient solution that is also uniform for all cases and avoids locking if I'm right about thread safety above. |
veanes
commented
Oct 28, 2021
Also, I forgot to add above, the nullability array would be |
veanes
commented
Oct 28, 2021
nullability array could also be flat, then it would need size 64 (3 bits per kind) then the lookup would directly use context (that is exactly ( |
6e4e4d8 to
4564b04Compareveanes
commented
Oct 28, 2021
@stephentoub, I updated the fix according to my last comment. I'm therefore asking for a re-review. It would be interesting to know the performance comparison after this change, assuming it is still thread-safe -- which it should be, as it replaces the earlier nullability dictionary with an array and gets rid of locking. I'm using |
4564b04 to
3052ed0CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
b93264b to
34b29ffCompareveanes
commented
Oct 29, 2021
@stephentoub : I took care of the comments and also simplified the initial test in |
94e6f8d to
0c1aa20CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e8d37ae to
970a4a8Compare
Added lock to protect
SymbolicRegexNode._nullabilityCachethat stores conditional nullability of a node for a given context, for thread-safety. This computation is not the common case as it only applies when the node (regex) starts with an anchor and can potentially be nullable (accept the empty string). Initial thought was to special case nullability for context 0 using a field but this is already covered in most common cases when the regex is neither nullable nor can be nullable that is checked before. The cache could potentially be moved to the builder as a shared cache to avoid the caches in the nodes but would then create bigger probability of thread contention at the builder level.