Skip to content

Optimize widgets (but better)#2239

Merged
robotboy655 merged 5 commits intoFacepunch:masterfrom
thecraftianman:optimize-widgets
Oct 8, 2025
Merged

Optimize widgets (but better)#2239
robotboy655 merged 5 commits intoFacepunch:masterfrom
thecraftianman:optimize-widgets

Conversation

@thecraftianman
Copy link
Copy Markdown
Contributor

@thecraftianman thecraftianman commented Mar 15, 2025

Based on (and supersedes) #915
Closes #2902

In addition to the changes made in the original PR, the following improvements have been made:

  • The filter function now uses a whitelist table instead of a function
  • The hooks handling widget processing are only added when widgets are in use
  • widgets.RenderMe is no longer necessary (its logic has been optimized and moved into the rendering hook directly) and has been stubbed out. I'm not sure if any addons that interact with this function even exist, so any suggestions on whether it should be kept functional, removed entirely, or kept stubbed out would be appreciated
  • All widget entities have had some amount of extra optimization done (mostly just reusing variables more often)

The widget system still won't be particularly performant, but it runs at least decently faster now, and manually removing the system entirely should no longer be necessary for a performance boost.

@robotboy655 robotboy655 added the Enhancement The pull request enhances current functionality. label Mar 17, 2025
Comment thread garrysmod/lua/entities/widget_base.lua Outdated
Comment thread garrysmod/lua/entities/widget_disc.lua Outdated
Comment thread garrysmod/lua/includes/modules/widget.lua Outdated
Comment thread garrysmod/lua/entities/widget_bones.lua
Comment thread garrysmod/lua/entities/widget_disc.lua Outdated
Comment thread garrysmod/lua/includes/modules/widget.lua
Copy link
Copy Markdown
Collaborator

@robotboy655 robotboy655 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Found this regression when testing for 1 second. (Just the widget.lua file)

The blue box is not supposed to appear.

@thecraftianman
Copy link
Copy Markdown
Contributor Author

thecraftianman commented Jul 31, 2025

There's a corresponding change in widgets_axis.lua (if I remember right) that fixes the issue with this particular widget. This should only affect this one widget because of the way that it attempted to prevent itself from being drawn before when widgets.RenderMe was still functional.

@robotboy655
Copy link
Copy Markdown
Collaborator

Do you not see the potential issues this can create with 3rd party addon content?

Backwards compatibility with existing content, hide the internal widgets list table
@robotboy655 robotboy655 merged commit 362a117 into Facepunch:master Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement The pull request enhances current functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TickWidgets are very CPU expensive

3 participants