-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Performance regressions in Quaternion.Conjugate and Quaternion.Negate #41738
Comments
Tagging subscribers to this area: @tannergooding, @pgovind |
This one is also a bit strange as there were no codechanges to these Quaternion methods between 3.1 and 5.0. I'm guessing there is some codegen change by the JIT instead. |
@jeffschwMSFT Is this being reviewed on your team or is there routing still needed here? Thanks! |
Looks like the Conjugate and Negate methods aren't being inlined in .NET 5, which is leading to the perf slowdown. However, as indicated the managed implementation hasn't changed and is actually rather simple: https://github.com/dotnet/corefx/blob/release/3.1/src/System.Numerics.Vectors/src/System/Numerics/Quaternion.cs#L124, so this is likely to do with one of the JIT changes. |
CC @dotnet/jit-contrib |
I'll take a look. |
Per ETL (for ConjugateBenchmark) : So will need to look at the jit dumps. |
In 3.1 we got a SIMD boost during inlining:
and we don't get this in 5.0
So need to dig in and figure out why we're no longer seeing this boost. |
It might be one of the changes I made with how the older SIMD intrinsics were handled. However, I find it a bit odd that it would have been recognized as SIMD anyways as |
The heuristics (used to?) take into account when SIMD arguments, locals or return values are present. |
Ah, it might actually be this bit: https://github.com/dotnet/runtime/blob/master/src/coreclr/src/jit/importer.cpp#L19301-L19303
In 3.1 we simply had bool isSIMDClass(CORINFO_CLASS_HANDLE clsHnd)
{
return info.compCompHnd->isInSIMDModule(clsHnd);
} In .NET 5, now that they are in S.P.Corelib, we are instead doing the following: https://github.com/dotnet/runtime/blob/master/src/coreclr/src/jit/compiler.h#L8057-L8066 bool isSIMDClass(CORINFO_CLASS_HANDLE clsHnd)
{
if (isIntrinsicType(clsHnd))
{
const char* namespaceName = nullptr;
(void)getClassNameFromMetadata(clsHnd, &namespaceName);
return strcmp(namespaceName, "System.Numerics") == 0;
}
return false;
} So while the new code is technically more correct in the checks, it causes various Quaternion, Plane, Matrix4x4, and Matrix3x2 to no longer get the "simd boost" they were getting previously. |
The simplest fix is likely to just mark In the case of something like Are there any concerns with this approach or would an alternative be better? |
So we were sort of boosting "by accident" in 3.1. Clearly this was beneficial for perf; not sure about code size, but typically we reason that anyone using these types cares about perf and so would like the jit to be a bit more aggressive. If we want to make this deliberate then we can intrisinfy the remaining types, I think that's a reasonable fix. I also wonder if we're checking consistently. The args case currently does if (lvaTable[lclVarTree->AsLclVarCommon()->GetLclNum()].lvSIMDType) while the locals and return value are checked via |
It looks more like it was intentional than by accident, given the associated comment.
👍, most of these types should eventually be intrinsified anyways (although whether that happens via proper intrinsic recognition or via HWIntrinsics in managed code is probably somewhat up in the air still).
It looks like they are different, yeah. From what I can tell, It looks like |
@tannergooding can you work up a fix? I'm OOF the next few days. Seems like this might clear the RC2 bar. I would just add the |
I've put up #41829 and validated that it was working:
|
Thanks! |
Relabeling to system.numeric since the fix is in that code. |
Tagging subscribers to this area: @tannergooding, @pgovind |
It looks like
Conjugate
andNegate
methods of theQuaternion
type have regressed compared to 3.1.@tannergooding could you please take a look and triage it? I assume that this might be acceptable similarly to #39035 but I don't have enough knowledge to make any decisions here.
Repro
To see all the numbers please click "details" below:
System.Numerics.Tests.Perf_Quaternion.ConjugateBenchmark
System.Numerics.Tests.Perf_Quaternion.NegateBenchmark
System.Numerics.Tests.Perf_Quaternion.NegationOperatorBenchmark
@DrewScoggins this regression did not get detected by the bot as it was added very recently 👍
The text was updated successfully, but these errors were encountered: