FortyTwoFortyTwo / Randomizer

TF2 plugin that randomizes player loadout in any imaginable combinations
GNU General Public License v3.0
35 stars 15 forks source link

On Linux, Optimization issue? #84

Closed gaejuck closed 2 years ago

gaejuck commented 2 years ago

When the number of players 24, lag begins. When there are more than 30 players, becomes hard to play. Reason is unknown because no log appears. Performance of the server computer is not bad either. What's the problem?

FortyTwoFortyTwo commented 2 years ago

It is likely because of optimization, very beefy server can run full randomizer server most of the time, still had rare lags. Not just linux, but my local windows also couldn't handle well with many bots alive. It probably will be tough to optimize this plugin, likely source is just lots of hooks being called like 100 times for each clients every frame.

FortyTwoFortyTwo commented 2 years ago

So for the past few weeks, I had investigated that lags largely seems to be from 2 detours, CTFPlayer::IsPlayerClass and CTFPlayer::GetEntityForLoadoutSlot.

Before I thought it would be tough to remove both detours while keeping bug-fixes, but I realize fixing CTFPlayer::GetEntityForLoadoutSlot is actually really easy to do: Complete remove without any other modifications.

CTFPlayer::GetEntityForLoadoutSlot detour was needed before to fix Jungle Inferno weapons and m_flItemChargeMeter, but after adding multiple weapons support, I never noticed that CTFPlayer::GetEntityForLoadoutSlot detour is now unneeded when plugin already handled multiple weapons. Although removing this detour may open new bugs that was using this detour I'm unaware of, we'll see.

As for the other detour CTFPlayer::IsPlayerClass though, this one detour was really helpful to fix multiple bugs, so simply removing it won't be simple. Best solution probably is to memory patch it, toggle on and off when needed to always return true.

gaejuck commented 2 years ago

oh thats nice

Kenzzer commented 2 years ago

As for the other detour CTFPlayer::IsPlayerClass though, this one detour was really helpful to fix multiple bugs, so simply removing it won't be simple. Best solution probably is to memory patch it, toggle on and off when needed to always return true.

I'm assuming, you're likely to use my mem patch inc, although even if you make your own, that entails the use of StoreToAddress regardless, and that function is arguably really slow. So if the intent is to turn off & on a memory patch regularly, you're going to keep having lags. Thankfully, later versions of SM are going to offer a faster StoreToAddress but as it stands right now, I don't advise using mem patch in the scope of rapid enabling/disabling.

Good luck solving everything else though!

FortyTwoFortyTwo commented 2 years ago

I'm assuming, you're likely to use my mem patch inc, although even if you make your own, that entails the use of StoreToAddress regardless, and that function is arguably really slow. So if the intent is to turn off & on a memory patch regularly, you're going to keep having lags. Thankfully, later versions of SM are going to offer a faster StoreToAddress but as it stands right now, I don't advise using mem patch in the scope of rapid enabling/disabling.

Indeed it still lags in 1.10, although it seems to slightly lag a bit less than detour, can't quite confirm it. I already had progress on this, so may well then push memory patches to master and wait for 1.11 to become stable for new parameter.

FortyTwoFortyTwo commented 2 years ago

Another source I found from lags is getting attributes, more specifically TF2_IndexFindAttribute stock get called way too many times. Used SDKCall CAttributeManager::AttribHookValue<float> instead, much quicker with caches instead of TF2_IndexFindAttribute. Changes is currently in dev branch and not master because there a lot of changes, but will be merged when whole branch is ready.

FortyTwoFortyTwo commented 2 years ago

Well it's been a while, but SM 1.11 is finally stable a few weeks ago, so StoreToAddress issues can be resolved. Should hopefully now have much less lags from it.