{"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":22,"created_at":"2015-03-19T21:48:10Z","updated_at":"2015-03-23T22:10:15Z","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\r\n\r\n__Tasks__:\r\n\r\n- [ ] ```Select```: add iterators for ```List<T>```, ```Array[T]```, ```ICollection<T>``` and  ```IReadOnlyCollection<T>```;\r\n- [ ] ```ToArray```, ```ToDictionary```: add special support for ```IReadOnlyCollection<T>``` to get the initial capacity;\r\n- [ ] ```ToList```: add special support for ```IReadOnlyCollection<T>``` to get the initial capacity (separated as it will affect _System.Collections.Generic_);\r\n- [ ] ```OrderBy(Descending)/ThanBy(Descending)```: implement ```IReadOnlyCollection<T>``` to propagate ```Count```;\r\n- [ ] ```Cast```, ```Reverse```: add iterators for ```ICollection<T>``` and  ```IReadOnlyCollection<T>``` to propagate ```Count```;\r\n- [ ] ```Range```, ```Repeat```: add an iterator that implements ```IReadOnlyCollection<T>```;\r\n- [ ] ```Skip```, ```Take```: add an iterator that implements ```IReadOnlyCollection<T>```;\r\n- [ ] Add performance tests for _System.Linq_\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/85225831","html_url":"https://github.com/dotnet/corefx/issues/1182#issuecomment-85225831","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/1182","id":85225831,"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-23T22:10:15Z","updated_at":"2015-03-23T22:10:15Z","body":"> I checked how performance tests implemented in other projects and found that they all done in the same way.\r\n\r\nSounds good. I didn't actually look. What projects already have perf tests?\r\n\r\n> Actually, I haven't found a way to run tests inside VS, so I always run them using the stated command.\r\n\r\nYou can run tests in VS15 by setting test project as Startup Project and just running debug session.\r\n\r\nFor perf tests it's important to compile using Release flavor and run them outside of devenv. Can you add a command that can be used to do that into your Pull Request + update first post in this issue when it's accepted?"}}