Request: Multithreading support. Can't believe so few mentioned it yet.
Dark_Ansem
Member Posts: 992
Back in 2002 NWN showed already that it could consider multithreading as a viable possibility for performance. With this re-release and the promise of getting a 64bit exe, why shouldn't it be possible for better and more multithreading to happen for this re-release?
4
Comments
TR
https://trello.com/c/I3VnBseh/130-multithreading-support
TR
I'm curious about something, and I think only somebody familiar with the code would be able to answer it. Maybe @JuliusBorisov could answer? Would multi-threading actually help? Like can the AI and server deal with running as more than one thread? Would it actually show a benefit, say allowing more players to be on a server, or for massive battles with hundreds of AI controlled combatants? Just wondering before I vote for precious developer resources to be used on something.
Much like many popular "quotes" actively used today It has become allegorical and serves its purpose regardless.
NWN being single threaded is a bottleneck the community has no ability to mod around it.
"Judge me by my intent. Not my shotgun." - Ghandi
AI updates and pathfinding are bottlenecks on the server, and this can be split onto different threads, mostly. This will benefit big PWs some.
On the singleplayer side, splitting the client and the server (in SP you run both) onto separate threads wouldn't too hard, but the benefit here is questionable. For most SP modules, the bottleneck is the graphics, and the server that the SP runs is orders of magnitude simpler than a PW. This would likely only help if people want to run an unoptimized PW in singleplayer - in which case, they can just run it in local multiplayer.
Graphics cannot be parallelized (with the exception of some weird hacks in the shadow engine), and you will not get better FPS with prettier VFX or more lights. If this is a perf hog, it should be approached in a different way.
The 64bit+multithreading is constantly requested, but it will not do any of the things you think it will do. You should be requesting features (i.e. "make the game run faster") rather than implementations. Multithreading as a feature on its own is useless.
In fact, it is perfectly possible the 64bit program will be _slower_ than the 32bit one, due to more data needing to be transfered in some cases. This won't be noticeable if it happens, but neither will be any speedup from the 64bit.
Whether the actual impact itself will be observable is unknown without hard measurements. We may get some 'magical speedups' simply compiling with a more modern compiler that has a better optimizer, although the same would be true for 32-bit code as well. The slow-down, if any, would be best observed measuring against a 32-bit build with the same compiler.
So in practice, I doubt we will see much actual impact on performance going to 64-bits on software of this era, although it is fun to speculate.
TR
Probably the biggest issue is that game code is notoriously full of very specific performance hacks, and all of those hacks will be optimized for 32-bit data layouts. On the other hand, if they are designed to make most efficient use of cache memory on the CPU, modern caches dwarf those of the era when the infinity engine was created, which is why I doubt the effect will be observable in practice.
There is a "magical speed-up" coming from the fact that you have twice as many registers at your disposal. When you use variables in a program, they are kept in registers. When you run out of available registers, some least used stuff is moved to memory. Compilers are really good at this shuffling, but having more registers is almost always better as you have less to move to memory.
Additionally, 64bit ABI is a bit more optimized than the x86 ones. This means that every time you call a function, you might end up saving a cycle or three.
To sum up, 64bit pros:
- More virtual memory available
- More registers available
- Faster parameter passing when calling functions
64bit cons:
- Larger pointers means less cache usage
- Larger binary code size.
It is perfectly possible to write a program that hits all the cons and none of the pros (I can make you one if you're really interested). Usually though, all of it is so minuscule you'll never notice.
By the way, there is also something called x32, which is a 64bit program with 32bit pointers. It's not very widespread though.
Source: I do this crap for a living.
@TarotRedhand I don't quite follow? Are you saying you want multithreading added in case it might become useful in the future? Adding more threads is literally a single line - in fact NWN already runs over 20 threads for network, sound, and so on. There's no point in creating threads you've no use for. I mean, they can always just mine cryptocurrency on the unused cores, but that's hardly what anyone had in mind.
https://software.intel.com/en-us/articles/the-secrets-of-parallel-pathfinding-on-modern-computer-hardware
*Edit* for example, C++ did not get standard support for concurrency/parallelism until 2011, a full year after the article, and parallel algorithms were added only a month or two ago when the new standard was published.
Process? (mostly symmetrical)
Thread? (mostly cluster - type 1 asymmetrical)
Threadlet? (mostly grid - type 2 asymmetrical)