-
Notifications
You must be signed in to change notification settings - Fork 538
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
Investigate the conversion between SKMatrix44 and Matrix4x4 #2778
Labels
tenet/performance
Performance related issues
Comments
I created a benchmark: [Benchmark(Baseline = true)]
public SKMatrix44 UseNewStruct()
{
SKMatrix44.UseUnsafeAs = false;
SKMatrix44 TheSKMatrix44 = SKMatrix44.CreateRotation(10, 20, 30, 0.7f);
var inverted = TheSKMatrix44.Invert();
return inverted;
}
[Benchmark]
public SKMatrix44 UseUnsafeAs()
{
SKMatrix44.UseUnsafeAs = true;
SKMatrix44 TheSKMatrix44 = SKMatrix44.CreateRotation(10, 20, 30, 0.7f);
var inverted = TheSKMatrix44.Invert();
return inverted;
} And edited the code of public static bool UseUnsafeAs = false;
public static implicit operator Matrix4x4 (SKMatrix44 matrix) =>
UseUnsafeAs ? Unsafe.As<SKMatrix44, Matrix4x4> (ref matrix) :
new Matrix4x4 (
matrix.m00, matrix.m10, matrix.m20, matrix.m30,
matrix.m01, matrix.m11, matrix.m21, matrix.m31,
matrix.m02, matrix.m12, matrix.m22, matrix.m32,
matrix.m03, matrix.m13, matrix.m23, matrix.m33);
public static implicit operator SKMatrix44 (Matrix4x4 matrix) =>
UseUnsafeAs ? Unsafe.As<Matrix4x4, SKMatrix44> (ref matrix) :
new SKMatrix44 (
matrix.M11, matrix.M21, matrix.M31, matrix.M41,
matrix.M12, matrix.M22, matrix.M32, matrix.M42,
matrix.M13, matrix.M23, matrix.M33, matrix.M43,
matrix.M14, matrix.M24, matrix.M34, matrix.M44); The results:
|
mattleibow
added a commit
that referenced
this issue
Mar 2, 2024
mattleibow
added a commit
that referenced
this issue
Mar 4, 2024
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Right now we are creating a new struct each time, but it may be better to use
Unsafe.As
:We need to benchmark and make sure.
The text was updated successfully, but these errors were encountered: