MonoGame icon indicating copy to clipboard operation
MonoGame copied to clipboard

CPU Usage DrawString runaway effect

Open MutsiMutsi opened this issue 6 months ago • 4 comments

Prerequisites

  • [x] I have verified this issue is present in the develop branch
  • [x] I have searched open and closed issues to ensure it has not already been reported.

MonoGame Version

3.8.4

Which MonoGame platform are you using?

MonoGame Cross-Platform Desktop Application (mgdesktopgl)

Operating System

Windows

Description

Drawing text with SpriteFont leads my CPU usage to spike up to full single core utilization. This happens seemingly randomly, suddenly the usage starts climbing until it caps out.

It seems to happen faster and more often with dynamic text, but it can be reproduced on my machine with the simplest imaginable example of just drawing a string.

Attached you can find a sample which on my machine more consistenently and faster reproduces the issue. I would say about half the times I run this sample in Debug or in Release build, it will start climbing in CPU usage from the get go.

I've also run this sample against MG 3.8.1, with no perceived changes in behaviour. CPU profiling points to all CPU resources being consumed at FlushVertexArray

Steps to Reproduce

Draw string with SpriteFont, wait till CPU usage runaway effects occurs.

Image

Minimal Example Repo

No response

Expected Behavior

No runaway cpu usage

Resulting Behavior

CPU core usage is maxed out

Files

fonttest.zip

MutsiMutsi avatar Aug 01 '25 12:08 MutsiMutsi

I tested this a few times on my mac (left it running for a hour once). No change, it remains pretty stable. Might be a windows thing?

dellis1972 avatar Aug 01 '25 17:08 dellis1972

@dellis1972 i had never encountered this before myself, but now it seems I can't get rid of it, it's entirely possible that it's an issue with my machine and that it can't be replicated elsewhere. It's perplexing either way.

MutsiMutsi avatar Aug 01 '25 21:08 MutsiMutsi

@nkast kindly provided me with the same sample in KNI, same result.

Image

MutsiMutsi avatar Aug 02 '25 08:08 MutsiMutsi

Confirmed this runaway issue does not happen MG WindowsDX, but it must be noted that the performance is still poor bouncing between 0.2% and somtimes spikes up to nearly 4% utilization (half a core of my 5800x3d for not much more than 100 chars rendered).

I've made one more change to the sample for more reliable testing; this.InactiveSleepTime = TimeSpan.FromSeconds(0f);

The rest is all the same. but this time its WindowsDX 3.8.4, so conslusion, no runaway full core utilization, but still high CPU and GPU usage, high power draw from my machine, to draw a small string.

Image

MutsiMutsi avatar Aug 02 '25 08:08 MutsiMutsi