-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Godot's .NET math types are way slower than System.Numerics #69490
Comments
Can you reproduce this in 3.5.1 which uses Mono? |
We could probably use SIMD to speed things up a bit, note that SIMD is also not implemented on the C++ side of the engine, there is a proposal for that godotengine/godot-proposals#4563 but it likely won't affect C# since we reimplement the math in order to avoid marshaling. If you really need the performance, there's nothing wrong about converting your inputs into |
Happy to provide input here and/or recommendations for implementation (whether for C/C++ or C#). Recently completed a large multi-release refactoring of the general backing JIT code for System.Numerics and a more general rewrite of Matrix3x2 and Matrix4x4 for .NET 8 that resulted in up to 48x faster code for some APIs and of course that's all MIT as well so shouldn't be overly complicated to port to godot if necessary. Edit: For those unaware, I'm the owner of the System.Numerics and System.Runtime.Intrinsics namespaces on the .NET libraries team. Love what's been going on in godot land and congrats on the 4.0 release! |
I'm taking a look at this as part of #79395. I have a suite of benchmarks that compares:
Summary:
@tannergooding I'll contact you if these problems are not solved with next preview (or RC). Thanks. Results: (example ported to C#, 512x512px) Lines 3646 to 3692 in 725beaa
|
Sounds good, thanks! You can notably get nightly builds here as well: https://github.com/dotnet/installer#installers-and-binaries Also glad to see the improvements done in .NET 8 are paying off. Did quite a bit of refactoring and improvements, particularly to |
^ .NET 8 is out now. Edit: Nevermind, seems like Godot vectors are already quite good according to AbeniMatteo tests. |
Maybe some implicit cast from Numerics would be nice |
@tannergooding If you're ever bored, you might take a look at System.Numerics.Vector3.Cross(). It's the only method that we're able to get noticeably faster performance from a custom function by converting to Vector128 and back. I believe the Numerics version is still only using scalar instructions. |
This was done in dotnet/runtime#103527, as was several other improvements including to matrix multiplication. It should be available in .NET 9 Preview 6. |
Agree, is there a separate issue/discussion tracking that? I haven't found one yet, but there's a lot of different terms to search for. I guess that'd go in the proposals repo? I was just doing some work to keep my game logic in an isolated C# project and was going to leverage the System.Numerics Vector3 to store my resulting data. It'd be nice if I could just directly assign it to the Node3D transforms and such within my game project layer. I guess the question would be if implicit operators would be wanted, someone could run into issues with perf if they're not aware it's creating/converting behind the scenes, but an explicit conversion operator and/or extension method public static class VectorExtensionMethods
{
public static Godot.Vector2 ToGodotVector(this System.Numerics.Vector2 v) => new(v.X, v.Y);
public static Godot.Vector3 ToGodotVector(this System.Numerics.Vector3 v) => new(v.X, v.Y, v.Z);
} |
Godot version
4.0 beta 6
System information
Win 11, Ryzen 5 5600H, 32GB RAM
Issue description
Godot's integrated math library for .NET 6 is considerably slower than standard .NET System.Numerics.
Steps to reproduce
Do pretty much any Vector ops and compare it against System.Numerics. See included project for a small benchmark.
Minimal reproduction project
VectorBenchmark.zip
The text was updated successfully, but these errors were encountered: