Skip to content

Casting to a variant generic interface is much slower than to non-variant #4090

@ikopylov

Description

@ikopylov

In the CoreFx issue (https://github.com/dotnet/corefx/issues/1182) was the idea to do explicit check whether IReadOnlyCollection<T> interface is supported. But it was rejected due to the slow casting to a variant generic interface. According to my tests it is ~20 times slower than casting to non-variant.

Source code of the test: CastToInterfaceTest.cs
Test results:

Cast From Cast To Is Variant Total time (ms)
List<int> ICollection<int> false 560
List<double> ICollection<int> false 1290
Thread IReadOnlyCollection<int> true 9713
List<int> IReadOnlyCollection<int> true 21988
List<double> IReadOnlyCollection<int> true 24294

It would be great to see some improvements here.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions