YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

Inexplicably high idle CPU usage for games #5053

Open mrgriva opened 7 months ago

mrgriva commented 7 months ago

Description

I've recently began to switch from GMS 1.4 to the latest version of GameMaker and after importing my project and testing it with a couple of people I noticed that my server was struggling. A quick explanation --- I'm renting a cheap Windows VM to host a server for my game (it's a normal .exe but I'm running it with no window and making it process only the essential stuff).

Using the 1.4 build the server could support a decent amount of players, but now it was struggling with only 3-4. I've narrowed the problem down to the base CPU usage of games built using newer versions of GameMaker (GM2+). How?

I've created 2 blank projects (1 room, no objects) - one using GMS 1.4 and the other one using the latest version. Built the executables and tested their CPU usage. The 1.4 build used 3-4% CPU on my VM, while the other one used 40-50%.

So half of the CPU usage on my server machine is just the empty project without executing any game logic or drawing... no wonder my actual game was choking with only 4 players.

I've repeated the same test on my Windows desktop and two of my old laptops (also Windows 10) with similar results. Blank GameMaker games now use around 10x CPU compared to GMS 1.4.

What have I tried to mitigate this issue:

The only thing that slightly lowered the CPU usage was lowering my game speed. I managed to get 25-30% CPU usage instead of the usual 40-50% by having my game run at 20FPS.

I don't understand why a full game built using GMS 1.4 hosting a server with 10 players equals to the CPU usage of an empty GMS2+ game. I would really appreciate a solution.

package.zip

Expected Change

No response

Steps To Reproduce

  1. Build 2 empty games, one using GMS 1.4 and the other using the latest GameMaker version
  2. Launch the executables and check their CPU usage

How reliably can you recreate this issue using your steps above?

Always

Which version of GameMaker are you reporting this issue for?

2024.2.0 (Monthly)

Which platform(s) are you seeing the problem on?

Windows

Contact Us Package Attached?

Sample Project Added?

attic-stuff commented 7 months ago

a totally empty project on my machine tops out at 3% CPU usage, and my machine is oldddddd, not even eligible for a windows 11 upgrade haha. are you sure you're not running into a hardware issue?

mrgriva commented 7 months ago

I did some more testing and I think we're both wrong.

It has nothing to do with hardware. The VM I'm using as my game server is VEEERY slow, but that's because it's cheap to rent. My actual PC is 2 months old and very high end and I recorded around 7% CPU usage on average for an empty project.

I found that it has EVERYTHING to do with the fact that I only tested GameMaker in "headless" mode!

This is how I have my server set up. Headless meaning that I don't create a window for my game, neither do I process any drawing or draw events (you can do this by calling "draw_enable_drawevent(false)" when the game starts).

I found that for some reason NOT creating a window INCREASES CPU usage... weird. If I launch my game normally it sits comfortably around 20% CPU usage on my server VM / around 1% on my actual PC. This still higher than an empty GMS 1.4 build which uses only around 5% CPU on my VM.

This is definitely still an issue because why would having a window open use less CPU than not creating one at all. Is GameMaker constantly checking whether it should create a window every frame or something? Even if it is why would checking that slow the game down so much?

attic-stuff commented 7 months ago

This is definitely still an issue because why would having a window open use less CPU than not creating one at all. Is GameMaker constantly checking whether it should create a window every frame or something? Even if it is why would checking that slow the game down so much?

yeah gamemaker does not support a true headless mode, not the current runtime. for your server to run truly headless and cheap and fast you will want to run a linux build on a linux service using xfvb to make it real headless.