-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Why is array still covariant? #41565
Comments
Tagging subscribers to this area: @safern, @ViktorHofer |
This would be an absolutely massive breaking change that would affect libraries and applications all the way up and down the stack. Array writes are already highly optimized and the performance gains for most applications would be negligible, so this doesn't justify the break. For applications which really do need to eke out these extra few percentage points, you could always cast the |
I didn't mean runtime internal massiveness.
#23393
|
@RamType-0
So what do you mean?
If a platform is not updated to use fast span, what makes you think it will be updated to use invariant arrays? If you're suggesting something that does not require updating the platform, then I think you need to be clearer about what that is. |
I mean runtime compatibility.(e.g. Process.Start no longer accepts uri by default in .NET Core. I think that was huge breaking changes.)
The solution Replacing T[] by Span'<T'> requires to be implemented by library provider,and would rather make lower performance in slow-span platform. The solution treating array as invariant doesn't requires any update by library provider,and also never make lower performance of any other platform.
I'm pretty sure that |
To be clear, I mean that any breaking change in fundamental type like array will be extremely huge. |
Have you ever wrote a code using array's covariantness? But I have not ever seen the code using the behaviour that "array is covariant". From the ancient of .NET Framework(after 2.0,which has generics), we know that array's covariantness is evil and waste,or most of us are just thinking array is invariant. That's why I think make array invariant is a minor breaking change. |
I think it is inconsistent to reject this feature by the reason you said in this issue.
If you really think so,you should also reject #23393 , isn't it? I think it is acceptable to reject this feature because of runtime internal implementation cost,or because of any other reliable reason. |
@RamType-0, #23393 does not change the way arrays work; it instead introduces a new type with different behavior.
.NET is getting faster at each release, but some of these performance improvements will inevitably require code changes to be fully taken advantage of. The slow span is not something we should be worried about; all frameworks implementing it (.NET Framework and .NET Core 1.X) are considered legacy (outright unsupported in .NET Core 1.X's case) and unsuitable for the development of new projects. And it's not that slow after all. |
I'm not comparing it with make array invariant. The solution make span from array is performant for any types, and doesn't require any overhead while convering it to array.
I think there are stiil
|
Oh,I was missing one ,UAP. |
No, but seen in BCL. In fact, the implementations of But, answering "no" for myself isn't enough for this question. If we do want to introduce "array invariant mode", the first step must be investigating a very large amount of libraries (both open and closed source). |
I know that of |
@RamType-0 Can you clarify the particular question being asked here? So far I think we've addressed two questions.
Did we correctly understand the question being asked? |
@RamType-0, could you also tell us what do you need invariant arrays for? What kind of performance-critical code are you working on, for which platform, and why is using a Moreover, how much optimized is your code? There is a chance that the variant array check is not your bottleneck. Have you tried |
Yes, I have for performance in Unity. |
Did You mean that you have wrote a code using array's covariantness,and that will not work if we make it invariant? Also, I'm proposing this feature for .NET Core,will not affect Unity.
I'm not requiring such a type any more,but if you think
I'm proposing make standard It was very hard to find broken Process.Start statically (it has no changes for its signature),but I think finding broken array's covariant usage would be found statically ,and easily. |
I got unexpectedly low performance for WithRef in this benchmark. BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19041.450 (2004/?/20H1)
Intel Core i9-9900K CPU 3.60GHz (Coffee Lake), 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=5.0.100-preview.8.20417.9
[Host] : .NET Core 3.1.7 (CoreCLR 4.700.20.36602, CoreFX 4.700.20.37001), X64 RyuJIT
Job-UBSNUT : .NET Core 3.1.7 (CoreCLR 4.700.20.36602, CoreFX 4.700.20.37001), X64 RyuJIT
InvocationCount=1 UnrollFactor=1
Maybe this because of covariant array. |
This benchmark seems fishy to me. On the first run, it calls a delegate from an array, and then it sets it to null, causing almost always an exception. The overhead raising and immediately catching an excpetion quite certainly dwarfs the overhead of arrays being covariant. In other words, the provided benchmarks failed to demonstrate the performance impact caused by the arrays' covariance. Try chaning the benchmarks so that the delegates are not set to null but simply called. You could add It also seems to me that you are a Unity developer and mostly concerned about Unity's performance. Unfortunately there is not much we can do, apart from waiting from them to add support for .NET Standard 2.1 which was said to take quite a lot time. |
Can't you see [IterationsSetup]? Using external dll from package often resulted in assembly confliction in Unity. |
Oh, yeah, I just realized the array was reset after each iteration. |
Covariant array make lower performance of almost any scenario.
It seems that .NET Core already has many larger breaking change than covariant array,why is it still maintained?
The text was updated successfully, but these errors were encountered: