-
In #110197, runtime/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs Lines 2221 to 2283 in c02569b I noticed that this following code would be not vectorized string str1 = "abc";
string str2 = "def";
string[] array = [str1, str2];
array.Contains(str1, ReferenceEqualityComparer.Instance); Is that a GC limitation that reference search can't be vectorized or this optimization was not considered yet? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Beta Was this translation helpful? Give feedback.
it's not possible. You basically want to take some string "A" (needle), populate a vector with "A"'s address e.g.
{ 0xAAAABBBB, 0xAAAABBBB ... 0xAAAABBBB }
. and then run search. What if GC relocates strings at any point of time or two equal strings have different addresses? It won't update values in SIMD registers today (well, even if it could, it wouldn't be able to figure out that it needs to update the broadcasted values as well).So your search becomes opportunistic, it might help if you want to run some quick vectorized O(N) search and if it finds nothing - run slow O(N). But it doesn't sound great …