Jump to content

Implement Multithreading to this game


Recommended Posts

This game runs in a single-threaded process. I did a screenshot of system resources monitor when the game was running.

image.png.42d987f60e96134563c1b47597755e9a.png

This is inefficient. There is much lag in the late game because many computation tasks are in this one thread in a single logical core. Players who use low frequency CPUs will force all other players to be slow for synchronization. Therefore it is important to separate the game processes into many threads and take advantage of all logical cores. It will multiply the available computation power by the total number of logical cores - much faster! Less power will be used by the CPU because a lower frequency is enough to perform the necessary computations. 

There are many opportunities for multithreading in this game. For example, each thread manages the simulation progress of just one entity, then let all logical cores of the CPU share the pool of threads. Now, if there are 1000 entities on the map, one logical CPU core must compute all 1000 simulation calculations, so it runs slowly. If we do multithreading on a CPU which has 8 logical cores (4 cores 8 threads) then each logical core only needs to do 125 simulation calculations, each physical core needs to do 250 calculations on average. This is at least 4 times faster. The difference is more significant on CPUs with more cores.

  • Like 2
Link to comment
Share on other sites

Some tasks are done off of the main thread. (There is an overview.) The most computation (simulation and rendering) is done on the same thread.

Only one thread can work on a spidermonkey-context (where the simulation is computed). Copying data from one context to another is performance intensive (compared to not doing it). So splitting the tasks on a per unit level results in much overhead.

I think doing the rendering on a different thread has more chances to yeald an improvement.

I hope i didn't destroy your motivation. We can always use help. :)
Fell free to join The irc chanel or DM me.

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...