-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect IReadOnlyList<T> in the BCL #24793
Comments
The main reason for that is the performance overhead: every additional type cast adds its own cost and the cost of cast to variant generic interface is much higher. Corresponding issue https://github.com/dotnet/coreclr/issues/603 |
But going O(n) on a random access collection? |
Due to historical reasons all collections from BCL that implement LINQ is often used on a hot path, so an additional type check may result in regression for most use-cases. |
So what's the point I implementing |
@ikopylov That always sounds a bit weird to me because it suggests that If we can't add read-only interface check to existing I know my suggestion sounds stupid. Feel free to laugh at me. 😞 |
@rvhuang I don't think your suggestion is stupid. But I do think it has roughly zero chance of being included in corefx. That's because it might offer some performance improvements in theory, but it won't do that in practice. And it doesn't make sense to add an API whose only purpose is to improve performance, if it won't actually improve performance. And if you have a library of collections where |
@svick In fact performance is not the thing I wanted to point out. The actual one is here as I mentioned.
This is one thing that I would consider API design flaw as you can't implement |
Exactly! Same thing bother me with But performance also counts. Accessing a list in linear fashion when an index/count is available is waste of resources, especially with bigger lists (See |
I second that. I was just implementing a new class with only Implementing IReadOnlyList. If I also have to implement IList so I can use it with LINQ properly, the whole Idea of having a ReadOnly Interface is gone. |
This is related to #42254, I'm going to close this so that we can consolidate the conversation in one issue. |
The following condition appears in many variations plenty of times throughout the BCL, especially in LINQ, (From
ElementAt
):But there is also
IReadOnlyList<T>
which provides the same thing and is not considered because it doesn't overlap withIList<T>
, and the fact that random access is provided by it is neglected in the BCL.Why is that?
Similar to
ICollection<T>
andIReadOnlyCollection<T>
, see #23337.The text was updated successfully, but these errors were encountered: