{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/1579","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/1579/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/1579/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/1579/events","html_url":"https://github.com/dotnet/coreclr/issues/1579","id":107016905,"number":1579,"title":"Enumerating IDictionary Allocates","user":{"login":"benaadams","id":1142958,"avatar_url":"https://avatars.githubusercontent.com/u/1142958?v=3","gravatar_id":"","url":"https://api.github.com/users/benaadams","html_url":"https://github.com/benaadams","followers_url":"https://api.github.com/users/benaadams/followers","following_url":"https://api.github.com/users/benaadams/following{/other_user}","gists_url":"https://api.github.com/users/benaadams/gists{/gist_id}","starred_url":"https://api.github.com/users/benaadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benaadams/subscriptions","organizations_url":"https://api.github.com/users/benaadams/orgs","repos_url":"https://api.github.com/users/benaadams/repos","events_url":"https://api.github.com/users/benaadams/events{/privacy}","received_events_url":"https://api.github.com/users/benaadams/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-09-17T15:58:26Z","updated_at":"2015-09-18T03:58:01Z","closed_at":null,"body":"Enumerating ```Dictionary``` doesn't allocate; however casting to an ```IDictionary``` then enumerating allocates. Shouldn't it follow the same code path as ```Dictionary```?\r\n\r\n```csharp\r\nvar dict = new Dictionary<string, string>();\r\nvar idict = (IDictionary<string, string>)dict;\r\n\r\nfor (var i = 0; i < 1000000; i++)\r\n{\r\n    // Doesn't allocate\r\n    foreach (var item in dict)\r\n    {\r\n        ;\r\n    }\r\n}\r\n\r\nfor (var i = 0; i < 1000000; i++)\r\n{\r\n    // Allocates 998k\r\n    foreach (var item in idict)\r\n    {\r\n        ;\r\n    }\r\n}\r\n```\r\n\r\n![allocs](http://aoa.blob.core.windows.net/aspnet/idictinary-allocates.png)"},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/141336577","html_url":"https://github.com/dotnet/coreclr/issues/1579#issuecomment-141336577","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/1579","id":141336577,"user":{"login":"mikedn","id":9973420,"avatar_url":"https://avatars.githubusercontent.com/u/9973420?v=3","gravatar_id":"","url":"https://api.github.com/users/mikedn","html_url":"https://github.com/mikedn","followers_url":"https://api.github.com/users/mikedn/followers","following_url":"https://api.github.com/users/mikedn/following{/other_user}","gists_url":"https://api.github.com/users/mikedn/gists{/gist_id}","starred_url":"https://api.github.com/users/mikedn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikedn/subscriptions","organizations_url":"https://api.github.com/users/mikedn/orgs","repos_url":"https://api.github.com/users/mikedn/repos","events_url":"https://api.github.com/users/mikedn/events{/privacy}","received_events_url":"https://api.github.com/users/mikedn/received_events","type":"User","site_admin":false},"created_at":"2015-09-18T03:58:01Z","updated_at":"2015-09-18T03:58:01Z","body":"> The jit could resolve down one level; and bind to the strongly typed enumerator?\r\n\r\nIt could, in certain cases. This is related to devirtualization, see #1532 as well. \r\n\r\nThat said, if you want performance it's best to avoid interfaces. Code like the above may be optimized but such code doesn't make sense and similar code that does make sense is less likely to be optimized."}}