{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/361","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/361/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/361/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/361/events","html_url":"https://github.com/dotnet/coreclr/pull/361","id":59269306,"number":361,"title":"Improve performance of ByteEqualityComparer.IndexOf","user":{"login":"mburbea","id":213233,"avatar_url":"https://avatars.githubusercontent.com/u/213233?v=3","gravatar_id":"","url":"https://api.github.com/users/mburbea","html_url":"https://github.com/mburbea","followers_url":"https://api.github.com/users/mburbea/followers","following_url":"https://api.github.com/users/mburbea/following{/other_user}","gists_url":"https://api.github.com/users/mburbea/gists{/gist_id}","starred_url":"https://api.github.com/users/mburbea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mburbea/subscriptions","organizations_url":"https://api.github.com/users/mburbea/orgs","repos_url":"https://api.github.com/users/mburbea/repos","events_url":"https://api.github.com/users/mburbea/events{/privacy}","received_events_url":"https://api.github.com/users/mburbea/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/coreclr/labels/cla-not-required","name":"cla-not-required","color":"009800"}],"state":"open","locked":false,"assignee":{"login":"AlexGhiondea","id":8396979,"avatar_url":"https://avatars.githubusercontent.com/u/8396979?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexGhiondea","html_url":"https://github.com/AlexGhiondea","followers_url":"https://api.github.com/users/AlexGhiondea/followers","following_url":"https://api.github.com/users/AlexGhiondea/following{/other_user}","gists_url":"https://api.github.com/users/AlexGhiondea/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexGhiondea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexGhiondea/subscriptions","organizations_url":"https://api.github.com/users/AlexGhiondea/orgs","repos_url":"https://api.github.com/users/AlexGhiondea/repos","events_url":"https://api.github.com/users/AlexGhiondea/events{/privacy}","received_events_url":"https://api.github.com/users/AlexGhiondea/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-02-27T17:42:46Z","updated_at":"2015-03-06T16:07:15Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dotnet/coreclr/pulls/361","html_url":"https://github.com/dotnet/coreclr/pull/361","diff_url":"https://github.com/dotnet/coreclr/pull/361.diff","patch_url":"https://github.com/dotnet/coreclr/pull/361.patch"},"body":"`ByteEqualityComparer.IndexOf(byte[],byte,int,int)` is always called from `Array.IndexOf<Byte>(byte[],byte,int,int)` which already will perform all these bound checks. see #52 \r\n\r\nA lot of the time is inexplicably spent doing the extra bound checking and accessing the method via another function call indirection. \r\n\r\nThe current \"optimized\" memchr is indeed an improvement for long enough runs, but only while removing some of the checks and ideally the indirection. There might be a use for having a sort of direct access to the pointer version of the algorithm, so I don't necessarily suggest merging `ByteEqualityComparer.IndexOf` and `Buffer.IndexOf`. Ideally, since 32 bit targets are sort of abnormal these days, it might be useful to include a 64 bit LE optimized path (like I have in the gist mentioned in #52). \r\n\r\nWorst case, we can remove the optimized case entirely. For very large buffers it would be a downgrade in performance. \r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/77584099","html_url":"https://github.com/dotnet/coreclr/pull/361#issuecomment-77584099","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/361","id":77584099,"user":{"login":"mburbea","id":213233,"avatar_url":"https://avatars.githubusercontent.com/u/213233?v=3","gravatar_id":"","url":"https://api.github.com/users/mburbea","html_url":"https://github.com/mburbea","followers_url":"https://api.github.com/users/mburbea/followers","following_url":"https://api.github.com/users/mburbea/following{/other_user}","gists_url":"https://api.github.com/users/mburbea/gists{/gist_id}","starred_url":"https://api.github.com/users/mburbea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mburbea/subscriptions","organizations_url":"https://api.github.com/users/mburbea/orgs","repos_url":"https://api.github.com/users/mburbea/repos","events_url":"https://api.github.com/users/mburbea/events{/privacy}","received_events_url":"https://api.github.com/users/mburbea/received_events","type":"User","site_admin":false},"created_at":"2015-03-06T16:07:15Z","updated_at":"2015-03-06T16:07:15Z","body":"Well I was doing a SQLCLR project that saw a noticeable improvement by avoiding using `Array.IndexOf<byte>`. Since we were aiming for a safe binary I couldn't use the optimized code I wrote, and stuck with a simple naive for-loop. \r\n\r\nFrom my analysis, using reflector the only caller was `Array.IndexOf<byte>`\r\n\r\nAn alternative could be to just hoist the body of `Buffer.IndexOfByte` into the method body.  "}}