Perfomance issues XNA versus Monogame

Hello dear friends,
I have ported my minecraft clone to the Monogame framework and realized some little perfomance issues : Chiefly while generating the world; in XNA the generation for a 13x13 chunk-map (each chunk has a width and depth of 13 and a height of 256)
takes 0.67 seconds, in Monogame 2 !.

How can I optimize the code to achieve the same speed as in XNA?

I thank you in advance.

Post scriptum: The FPS is mostly similar(in comparison to xna), just the world-generation takes a “bit” longer.

You can analyze your code using a .NET performance profiler (such as Visual Studio, Redgate ANTS Performance Profiler, Jetbrains dotTrace, …) and find out how long each function is taking.

I suggest you create a performance profile of the XNA app and the MonoGame app and compare the profiles. If a MonoGame function is causing the slow down, you can create a new issue on Github.

1 Like

That makes me suspect the issue is the VertexBuffer/IndexBuffer SetData calls.

Let’s see what a profile shows.



I am sorry, my Visual Studio is only giving me these kind of information and analyzing processes.
The Monogame-versions are these with the titel “MinecraftCloneMonogame”.

Thank you in advance!
215

Looks like you only got the memory profile for the MonoGame build… that won’t help us. Like in your XNA build you need to look at the performance profile.

Uh, I guess, I know why.
The ContentPipline:

The picture above is in monogame.
Here are the results for XNA:



I am sorry,
here is the perfomance profile for monogame:

Those images still don’t tell me anything. We don’t need any memory profile images… memory usage isn’t going to tell us why it is slow.

The “Functions Doing The Most Individual Work” charts are what we need to see.

You mean on XNA VertexBuffer.CopyData is doing the most work and in MonoGame ContentManager.Load<Texture2D> is?

I did realize that I have uploaded the wrong screenshots.
My recent post shows the perfomance profile.

That seems like vertex/index buffer writing is the issue… SharpDX.Interop.Write is used for that.

Can you look at the Function list? It should show a lot more data.

Not that lot;
here is the hierarchy:




btw: Very nice editor !

Can you change to x64 and profile again?

How are you building your vertex buffers @PhiConst.NET? Can you show us how they are allocated and roughly how you are calling SetData?

It’s 64x profile( because these chunksarrays are greater than 2 Gigabyte).

@Tom
I will upload the XNA and Monogame source to github.
I guess it’s the best way to demonstrate the problem.

See ya in _ 5~15 mins.

http://pastebin.com/RAjLM3BM

EDIT; It’s the VertexBuffer:


The method: UpdateBoundingBox.

IF I REMOVE IT: 0.6 SECONDS!

It’s the Method GetData not SetData!

If I remove this method from DefaultCubeStructure… it takes 0.6 Seconds to generate the world.
With UpdateBoundingBox over 3 seconds!

You should really avoid calling GetData on any graphics resource… you are literally copying data back from GPU memory to CPU memory. This is not very fast at all.

We could maybe optimize things a bit more there, but DX11 is different from DX9 and it may just never be able to get the same performance as XNA with this. Even then… it will always be slower than already having this data in CPU memory… regardless of XNA or MonoGame.

Yes, that’s right.
Thank you man.