vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
467 stars 75 forks source link

Performance hit when used in .net core - SharpGLTF is much slower in .netcore than in .net framework #57

Closed AhmedMakhlouf closed 4 years ago

AhmedMakhlouf commented 4 years ago

SharpGLTF (1.0.0-alpha0018) is much slower in a .net core 3.1 project than in a .net framework 4.7.2 one.

When writing a file in .net framework, the function "SharpGLTF.Geometry.TrianglesPrimitiveBuilder::AddTriangle" takes 4.9 seconds.

Writing the same file in .net core 3.1 the same function takes 60 seconds.

I'm working in x64 release environment - Visual Studio 2019.

Tried both versions 18 (1.0.0-alpha0018) & 14 of SharpGLTF

"System.Numerics.Vector.IsHardwareAccelerated" is true in both applications.

vpenades commented 4 years ago

Using alpha0018, I've wrote this small test:

var mesh = new MeshBuilder<VG, VE, VE>();
var prim = mesh.UsePrimitive(MaterialBuilder.CreateDefault());

var sw = System.Diagnostics.Stopwatch.StartNew();

for(int i=0; i < 500000; ++i)
{
    var a = GetRandomPos();
    var b = GetRandomPos();
    var c = GetRandomPos();                

    prim.AddTriangle(a,b,c);
}

System.Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
In my machine, I get these results: framework milliseconds
netcore3.1 1838ms
net472 2215ms

So there must be something else that's causing that huge difference... could you give more details?

AhmedMakhlouf commented 4 years ago

You're right, I tested your code and I got similar results. I'll Will provide you with more details when I have time to do more investigating.

Thanks!