Page 1 of 1

Thread pooling?

Posted: 29 Nov 2019, 20:12
by samuraicrow
I've got an idea stuck in my head that would improve the performance on single-board computers (SBCs) and other computers with unified memory architectures. The basic idea is that every calculation based on a similar math function in a loop be given its own thread. That way the code cache of each core will hold only a small loop and probably compute it until completion for the current frame before needing to reload.

I know the pathfinder has already done that but what about the trajectory and collision calculations of mortars/bombard/howitzers/etc. Likewise the line-of-site weapons could be done similarly?

I know a little C++ but am not familiar with the code base for this program. It seems to run dual-threaded for now which seems to be a hangup on quad-core or better ARM systems.

Re: Thread pooling?

Posted: 29 Nov 2019, 20:40
by Cyp
The problem with threading is probably that it doesn't work very well with spaghetti code that messes with lots of random global variables hidden all over the place.

Re: Thread pooling?

Posted: 29 Nov 2019, 23:51
by Berserk Cyborg
In terms of overall performance it's probably the graphics code that is one of the worst offenders. Pastdue's gfx PR at least no longer makes Warzone melt one of my modern CPU cores, lol. Hopefully 3.4 comes after 3.3.1.

Pathing can be still be an issue, especially if a situation occurs where the micro-AI is continuously trying to path something to locations a unit can't get to, be it actually impossible or blocked off by a tree or feature gate (truck restoration and scouting order come to mind)...

Documentation on the source is scarce; You'll just have to wing it and learn as you go. Overall you'll probably find it difficult to continue with your idea at this time since it is not the most pristine example of a C++ application.
Cyp wrote: 29 Nov 2019, 20:40 The problem with threading is probably that it doesn't work very well with spaghetti code that messes with lots of random global variables hidden all over the place.
Is... is that whining I hear?! Well chop-chop Cyp, get to fixing it. That's an order! :P

Re: Thread pooling?

Posted: 30 Nov 2019, 08:02
by samuraicrow
Well! I suppose it might be easier to rewrite part of the engine using Rust instead. Sad.

Re: Thread pooling?

Posted: 30 Nov 2019, 10:47
by Cyp
Berserk Cyborg wrote: 29 Nov 2019, 23:51
Cyp wrote: 29 Nov 2019, 20:40 The problem with threading is probably that it doesn't work very well with spaghetti code that messes with lots of random global variables hidden all over the place.
Is... is that whining I hear?! Well chop-chop Cyp, get to fixing it. That's an order! :P
But I don't know how to fix threading, such that it can work very well with spaghetti code that messes with lots of random global variables hidden all over the place. It would probably at least involve needing to drastically improve the compiler's static analysis.