{"action":"created","issue":{"url":"https://api.github.com/repos/sq/JSIL/issues/657","labels_url":"https://api.github.com/repos/sq/JSIL/issues/657/labels{/name}","comments_url":"https://api.github.com/repos/sq/JSIL/issues/657/comments","events_url":"https://api.github.com/repos/sq/JSIL/issues/657/events","html_url":"https://github.com/sq/JSIL/issues/657","id":56430183,"number":657,"title":"Disproportionate performance between HashSet<int> and List<int>","user":{"login":"dbh1997","id":10538969,"avatar_url":"https://avatars.githubusercontent.com/u/10538969?v=3","gravatar_id":"","url":"https://api.github.com/users/dbh1997","html_url":"https://github.com/dbh1997","followers_url":"https://api.github.com/users/dbh1997/followers","following_url":"https://api.github.com/users/dbh1997/following{/other_user}","gists_url":"https://api.github.com/users/dbh1997/gists{/gist_id}","starred_url":"https://api.github.com/users/dbh1997/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbh1997/subscriptions","organizations_url":"https://api.github.com/users/dbh1997/orgs","repos_url":"https://api.github.com/users/dbh1997/repos","events_url":"https://api.github.com/users/dbh1997/events{/privacy}","received_events_url":"https://api.github.com/users/dbh1997/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-03T20:13:01Z","updated_at":"2015-02-03T20:18:46Z","closed_at":null,"body":"This isn't between C# and JS itself, but the difference in collection routines relative to each other.\r\n\r\nIn native C#, the Add function for HashSet<int> requires about 3x the time of an Add to List<int>.  In the JSIL converted code, the difference is about 25x (on Chrome).\r\n\r\nIterating the HashSet versus List in native C# is about 20% slower.  In the JSIL converted code it's nearly 50 times slower (again on Chrome).\r\n\r\nThe Random access (Contains function) appears to proportional with C# - providing a win starting at around 30 items in the list.  This is traditionally why somebody would pick this collection.\r\n\r\nIt might be the case there is nothing that can be done, but the shift in relative performance means that the first 2 scenarios have to be scrutinized and weighed against the access calls when deciding what to use.  Thought I would pass it on as it can at least be information for others to be aware of as well.\r\n\r\n\r\nAdd:\r\n\r\n           int sum = 0;\r\n\r\n            HashSet<int> set = new HashSet<int>();\r\n            //List<int> set = new List<int>();\r\n\r\n            for (int i = 0; i < 100000; i++)\r\n            {\r\n                set.Clear();\r\n                for (int j = 0; j < 1000; j++)\r\n                {\r\n                    set.Add(j);\r\n                }\r\n            }\r\n\r\nIterate:\r\n\r\n           int sum = 0;\r\n\r\n            HashSet<int> set = new HashSet<int>();\r\n            //List<int> set = new List<int>();\r\n            for (int j = 0; j < 1000; j++)\r\n            {\r\n                set.Add(j);\r\n            }\r\n\r\n            for (int i = 0; i < 1000000; i++)\r\n            {\r\n                foreach (var x in set)\r\n                {\r\n                    sum += x;\r\n                }\r\n            }\r\n            Console.WriteLine(sum);"},"comment":{"url":"https://api.github.com/repos/sq/JSIL/issues/comments/72726019","html_url":"https://github.com/sq/JSIL/issues/657#issuecomment-72726019","issue_url":"https://api.github.com/repos/sq/JSIL/issues/657","id":72726019,"user":{"login":"kg","id":198130,"avatar_url":"https://avatars.githubusercontent.com/u/198130?v=3","gravatar_id":"","url":"https://api.github.com/users/kg","html_url":"https://github.com/kg","followers_url":"https://api.github.com/users/kg/followers","following_url":"https://api.github.com/users/kg/following{/other_user}","gists_url":"https://api.github.com/users/kg/gists{/gist_id}","starred_url":"https://api.github.com/users/kg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kg/subscriptions","organizations_url":"https://api.github.com/users/kg/orgs","repos_url":"https://api.github.com/users/kg/repos","events_url":"https://api.github.com/users/kg/events{/privacy}","received_events_url":"https://api.github.com/users/kg/received_events","type":"User","site_admin":false},"created_at":"2015-02-03T20:18:46Z","updated_at":"2015-02-03T20:18:46Z","body":"The ideal implementation of HashSet and Dictionary in JS is to cross-compile the implementations from the native CLR. Right now we use native JS data structures and to put it simply, native JS data structures are garbage."}}