Facepunch / garrysmod-issues

Garry's Mod issue tracker
144 stars 56 forks source link

TickWidgets are very CPU expensive #2902

Open EstevanTH opened 7 years ago

EstevanTH commented 7 years ago

Details

Hi Rubat, hi Willox. I do not really know how relevant this performance issue is, but I'm going ahead. The serverside hook "TickWidgets" (event "PlayerTick"), defined in widget.lua at line 149 really is CPU expensive.

The quoted console log is generated by my Addon hooks Lag Finder. It shows that about 30% of the frame time is dedicated to handling widgets. The server runs the gamemode University RP, derived from DarkRP, derived from Sandbox. It runs with me and 127 bots. The tickrate is 20. The CPU is AMD K10 @ 2.5 GHz.

Here are the 16 laggiest hooks found during the last 343 frames:
 Identifier ------------------------------------------------------------ Impact  Executions  Mean t /f  Max time 
 Event "PlayerTick", hook "TickWidgets"                                  31.13%  43561       27231.25us 46455.7us
  in "lua/includes/modules/widget.lua" (lines 149 to 149),
  not found in Workshop addons
 Timer "59DarkRPCanHearPlayersVoice"                                     06.19%  35          552.236us  49206.5us
  in "gamemodes/darkrp/gamemode/libraries/fn.lua" (lines 109 to 111),
  not found in Workshop addons
 Timer "100DarkRPCanHearPlayersVoice"                                    04.58%  34          397.273us  5375.87us
  in "gamemodes/darkrp/gamemode/libraries/fn.lua" (lines 109 to 111),
  not found in Workshop addons
...

I do not think I am running any widget and bots do not need them anyway.

Steps to reproduce

You can install my Addon hooks Lag Finder if you are not convinced about the problem.

A few ideas to solve this

Well, I am not used to widgets. That said, I still understand the comments that explain the usage of widgets. I'm providing ideas to solve this, but I feel dumb because I can't find anything really good.

Momo ❤️

Bo98 commented 7 years ago

Relevant: https://github.com/garrynewman/garrysmod/pull/915

EstevanTH commented 7 years ago

I did not think to look there, thanks!

EstevanTH commented 7 years ago

Ohh I know why this is done serverside, basically! It is because the event "PlayerTick" is predicted! Widgets would not work in single player if the hook was not added serverside in single player.

Is this hook added on SP as well as MP, both serverside and clientside, for easier compatibility? I mean, in order to avoid the necessity to make 2 different codes for SP and MP.

EstevanTH commented 7 years ago

If it is never run on the client, why is there a hook.Add( "PostDrawEffects", "RenderWidgets", ... ) in the module and why is everything shared according to the wiki? 😮 I think that the widget module is included in garrysmod\lua\includes\init.lua, both serverside and clientside. Am I wrong or something?

Also I could not wait to publish my new addon Widgets Disabler (more CPU power!) 😄

Bo98 commented 7 years ago

Sorry, I mixed it up with another library.

mcNuggets1 commented 7 years ago

That is indeed heavy.

Kefta commented 7 years ago

@mcNuggets1 Just use an addon that removes the widget hook when it's not in use; the problem has been around since GM13 came out