{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/1182","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/1182/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/1182/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/1182/events","html_url":"https://github.com/dotnet/corefx/issues/1182","id":63098030,"number":1182,"title":"System.Linq performance improvement suggestions","user":{"login":"ikopylov","id":10262823,"avatar_url":"https://avatars.githubusercontent.com/u/10262823?v=3","gravatar_id":"","url":"https://api.github.com/users/ikopylov","html_url":"https://github.com/ikopylov","followers_url":"https://api.github.com/users/ikopylov/followers","following_url":"https://api.github.com/users/ikopylov/following{/other_user}","gists_url":"https://api.github.com/users/ikopylov/gists{/gist_id}","starred_url":"https://api.github.com/users/ikopylov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ikopylov/subscriptions","organizations_url":"https://api.github.com/users/ikopylov/orgs","repos_url":"https://api.github.com/users/ikopylov/repos","events_url":"https://api.github.com/users/ikopylov/events{/privacy}","received_events_url":"https://api.github.com/users/ikopylov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-03-19T21:48:10Z","updated_at":"2015-03-21T16:44:04Z","closed_at":null,"body":"With Linq-to-Objects it is quite common practice to perform a series of transformations, and then materialize sequence to a concrete collection type by calling _ToArray(), ToList(), ToDictionary()_. These operations would work much faster if they knew the number of elements in the sequence.\r\n\r\nCurrently System.Linq.Enumerable has special treatment for _ICollection\\<T\\>_ interface only. \r\nI suppose that additional support for _IReadOnlyCollection\\<T\\>_ can improve performance in some cases, because through it we can figure out the total number of elements.\r\n\r\nAnother problem with System.Linq is that in many cases the information about the number of elements is lost. One of the most common example:\r\n```C#\r\nList<int> source = ...;\r\nList<int> transformed = source.Select(o => o + 1).ToList();\r\n```\r\n\r\nObviously _Select_ does not change the number of elements in the sequence, but _ToList_ method cannot take advantage of that. Information is lost.\r\nIn this particular scenario, it would be great for _Select_ to return some _SelectIterator_ instance, which implements _IReadOnlyCollection\\<T\\>_, and thereby passes the number of elements to the subsequent methods.\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/84388969","html_url":"https://github.com/dotnet/corefx/issues/1182#issuecomment-84388969","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/1182","id":84388969,"user":{"login":"MarcinJuraszek","id":6841973,"avatar_url":"https://avatars.githubusercontent.com/u/6841973?v=3","gravatar_id":"","url":"https://api.github.com/users/MarcinJuraszek","html_url":"https://github.com/MarcinJuraszek","followers_url":"https://api.github.com/users/MarcinJuraszek/followers","following_url":"https://api.github.com/users/MarcinJuraszek/following{/other_user}","gists_url":"https://api.github.com/users/MarcinJuraszek/gists{/gist_id}","starred_url":"https://api.github.com/users/MarcinJuraszek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarcinJuraszek/subscriptions","organizations_url":"https://api.github.com/users/MarcinJuraszek/orgs","repos_url":"https://api.github.com/users/MarcinJuraszek/repos","events_url":"https://api.github.com/users/MarcinJuraszek/events{/privacy}","received_events_url":"https://api.github.com/users/MarcinJuraszek/received_events","type":"User","site_admin":false},"created_at":"2015-03-21T16:44:04Z","updated_at":"2015-03-21T16:44:04Z","body":"1. Good idea.\r\n\r\n2. `CopyTo` would still need to iterate over all elements because `selector` needs to be called on every element of `source` collection. Unless I'm missing something."}}