{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/5804","repository_url":"https://api.github.com/repos/dotnet/coreclr","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/5804/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/5804/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/5804/events","html_url":"https://github.com/dotnet/coreclr/pull/5804","id":160310229,"number":5804,"title":"Specialize IndexOf, LastIndexOf for the enum equality comparers","user":{"login":"jamesqo","id":9159214,"avatar_url":"https://avatars.githubusercontent.com/u/9159214?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesqo","html_url":"https://github.com/jamesqo","followers_url":"https://api.github.com/users/jamesqo/followers","following_url":"https://api.github.com/users/jamesqo/following{/other_user}","gists_url":"https://api.github.com/users/jamesqo/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesqo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesqo/subscriptions","organizations_url":"https://api.github.com/users/jamesqo/orgs","repos_url":"https://api.github.com/users/jamesqo/repos","events_url":"https://api.github.com/users/jamesqo/events{/privacy}","received_events_url":"https://api.github.com/users/jamesqo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/coreclr/labels/cla-already-signed","name":"cla-already-signed","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-14T23:50:05Z","updated_at":"2016-06-15T04:28:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dotnet/coreclr/pulls/5804","html_url":"https://github.com/dotnet/coreclr/pull/5804","diff_url":"https://github.com/dotnet/coreclr/pull/5804.diff","patch_url":"https://github.com/dotnet/coreclr/pull/5804.patch"},"body":"Overrides the internal `IndexOf`/`LastIndexOf` methods for `EqualityComparer`, so only one virtual method call is made as opposed to however many elements are in the array. I also made some other changes to bring the code in line with what I did in #5503, namely using `sealed` where applicable and not calling `Name` for `GetHashCode`.\r\n\r\n### Performance impact\r\n\r\nTest code:\r\n\r\n```cs\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Diagnostics;\r\nusing System.Reflection;\r\n\r\nnamespace ConsoleApplication\r\n{\r\n    public class Program\r\n    {\r\n        const int Index = Length / 2;\r\n        const int Length = 5000;\r\n        const int Iterations = 100000;\r\n        const int OuterIterations = 5;\r\n        \r\n        public static void Main(string[] args)\r\n        {\r\n            var array = new StringSplitOptions[Length];\r\n            array[Index] = StringSplitOptions.RemoveEmptyEntries;\r\n\r\n            for (int i = 0; i < OuterIterations; i++)\r\n            {\r\n                var watch = Stopwatch.StartNew();\r\n                for (int j = 0; j < Iterations; j++)\r\n                    Array.IndexOf(array, StringSplitOptions.RemoveEmptyEntries);\r\n                watch.Stop();\r\n                Console.WriteLine(watch.Elapsed);\r\n            }\r\n\r\n            Console.WriteLine();\r\n\r\n            for (int i = 0; i < OuterIterations; i++)\r\n            {\r\n                var watch = Stopwatch.StartNew();\r\n                for (int j = 0; j < Iterations; j++)\r\n                    Array.LastIndexOf(array, StringSplitOptions.RemoveEmptyEntries);\r\n                watch.Stop();\r\n                Console.WriteLine(watch.Elapsed);\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nBefore:\r\n\r\n```\r\n00:00:01.0684618\r\n00:00:01.0321808\r\n00:00:01.5014109\r\n00:00:01.9096960\r\n00:00:01.1151452\r\n\r\n00:00:01.0152761\r\n00:00:01.2019504\r\n00:00:01.0269755\r\n00:00:01.1227927\r\n00:00:01.2432870\r\n```\r\n\r\nAfter (5x speedup):\r\n\r\n```\r\n00:00:00.3152865\r\n00:00:00.2413720\r\n00:00:00.2654954\r\n00:00:00.2776022\r\n00:00:00.2525021\r\n\r\n00:00:00.2897419\r\n00:00:00.2840207\r\n00:00:00.2761021\r\n00:00:00.3039447\r\n00:00:00.2753199\r\n```\r\n\r\n@jkotas @omariom"},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/226085055","html_url":"https://github.com/dotnet/coreclr/pull/5804#issuecomment-226085055","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/5804","id":226085055,"user":{"login":"jasonwilliams200OK","id":2031765,"avatar_url":"https://avatars.githubusercontent.com/u/2031765?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonwilliams200OK","html_url":"https://github.com/jasonwilliams200OK","followers_url":"https://api.github.com/users/jasonwilliams200OK/followers","following_url":"https://api.github.com/users/jasonwilliams200OK/following{/other_user}","gists_url":"https://api.github.com/users/jasonwilliams200OK/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonwilliams200OK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonwilliams200OK/subscriptions","organizations_url":"https://api.github.com/users/jasonwilliams200OK/orgs","repos_url":"https://api.github.com/users/jasonwilliams200OK/repos","events_url":"https://api.github.com/users/jasonwilliams200OK/events{/privacy}","received_events_url":"https://api.github.com/users/jasonwilliams200OK/received_events","type":"User","site_admin":false},"created_at":"2016-06-15T04:28:22Z","updated_at":"2016-06-15T04:28:22Z","body":"> I really dislike this style\r\n\r\nMe too, so would probably K&R themselves .. but that's irrelevant because contribution guideline: https://github.com/dotnet/coreclr/blob/03cd4bc/Documentation/project-docs/contributing.md#dos-and-donts, point 2 say:\r\n\r\n> **DO** give priority to the current style of the project or file you're changing even if it diverges from the general guidelines.\r\n\r\nLooking at rest of the file `EqualityComparer.cs`, this style is heavily used."}}
{"actor":{"display_login":"jasonwilliams200OK"}}