-
Notifications
You must be signed in to change notification settings - Fork 82
Make the game ~3x faster #315
base: main
Are you sure you want to change the base?
Conversation
|
It's also worth mentioning that there is a good chance many of these changes can be ported to the aps++ rewrite. Should be pretty easy to port these manually, however if explicitly requested I can make a similar PR for that project. |
|
Almost all of this looks good to me!
Fully agreed, I think it'd be better to just make it a hashmap without any of the case-translation and without the change event. What could work is warning in console for setting dublicate convars. |
|
Yeah the color cache could absolutely be taken out of there to remove the IIFE. I did that to keep it isolated from the rest of the code as nothing else should ever need to read it. Also, almost always, IIFEs have no significant impact on performance, especially in cases like this where it's only initializing once. There's even the chance it helps performance by avoiding pollution of the higher scope, though we'd be measuring sub microseconds at that point... |
|
Woa! Thats a massive changing of codes, im very impressed, i will test it soon with the aps++ rewrite. |
|
Thank you! If you want any help or have questions about implementation ask me here or at my discord xskt. (DMs open!) |
|
Alright, i only see one problem with the "nearest" function, wich its not working properly on the rewrite. |
|
any other problems before i merge this? |
|
nearestDifferentMaster controller is lagging the server very hard if serveral entities uses nearestDifferentMaster controller, he may look foward to fix it, but otherwise there are no problems. |
You're misunderstanding. It's not that nearestDifferentMaster is any laggier than before. (It's actually faster than it was originally.) It's that now, after optimizing the other parts, it has become the slowest thing in comparison. |
|
Oh okay |
As far as I know there is not. Feel free to merge when the code has been reviewed in full. If there are any new issues discovered later, feel free to contact me on discord about it and I'll try to fix |
|
Great pull request! There are some good optimizations. On case with Below you can see that I'm benchmarking all controllers, not just |
|
Yea and that causes to lag a ton then the original nearestDifferentMaster |
|
Again just to clarify, because I'm not sure if you are just pinpointing the lag or claiming there is an issue present, this isn't new lag introduced by the PR. nearestDifferentMaster was actually optimized here. Previously it would iterate over all entities and perform a raw distance check while now it uses the hashgrid query function which is more efficient overall. What is happening is that after optimizing the other parts of the game, that before lagged even harder than this, nearestDifferentMaster has become the relatively most expensive part of the game loop. Not because it is worse, but because everything else that competed for compute time per tick in the game loop is faster now. |
|
If you say so. |
|
That literally makes no sense whatsoever. The whole point of a hashgrid is to be faster than O(n) scanning through entities, and even yourself say its faster when its used in collisions. It makes zero sense for it to be slower here, as its the same type of optimization. |
|
I'll look into it more later though, maybe the entire controller can be redone in a better way than it was originally. |
|
Not working, they stopped targetting entities |
|
It seems to work fine, but all the performance improvements come from cutting the range by half. const sqrRange = range * range;
const halfrange = range / 2;
const fourThirdsSqrRange = sqrRange * 4 / 3;
let mostDangerous = -1;
let finalTargets = [];With a for loop that looks like this
I think with collisions it sorts relatively small sizes compared to ranges which can get really big. |




This PR does a lot of invasive changes that drastically improve the performance of the game.
The source of this commit is mostly original, however some of it originates from my in-development game Polytanks.
Here is a Before and After image (look at server speed percentage). It's not a perfect demonstration, but you understand.
Before
After
There is further work that could be done such as reworking how socket views are handled and make them query the grid or reworking that
stupidoverly-detrimental-to-runtime-performance Proxy-config thing, however I got bored.