Skip to content

Conversation

@DarthTealc
Copy link
Contributor

@DarthTealc DarthTealc commented Sep 20, 2025

I've made a series of tweaks to optimise the performance and CPU/memory use of AngularJS in the Gmod menu.

Functionality and visuals should be identical., This is purely a set of performance optimisation updates. Improvements should hopefully be noticed on setups that currently find the menu a bit heavy.

Each commit is an individual step with details about what has been adjusted. Please view each commit if you want to know what it does.

Regarding jQuery, I've replaced jquery-3.7.1.min.js with jquery-3.7.1.slim.min.js - Please check against source here https://code.jquery.com/jquery-3.7.1.slim.min.js to verify what I've included is authentic and unmodified. If you're testing this but don't want to use the jquery change, you can keep your Gmod's current jquery without any issue as it's not required for the rest of the changes to work.

I have no further AngularJS-oriented changes planned, so there's not going to be a "step 2" PR after this. But I welcome any feedback/suggestions/contributions to improve this PR and I'll update it accordingly.

Please test and share if you find any regressions, or it doesn't work in Awesomium. I did not make any changes that should break in Awesomium, but I can't test it.

@DarthTealc DarthTealc marked this pull request as ready for review September 23, 2025 13:00
@DarthTealc
Copy link
Contributor Author

Unmarked as draft so it is able to be reviewed by others. I have had no issues myself so far.

The slim version excludes some modules that Gmod doesn't make use of, such as ajax and effects. You can validate this copy is authentic by matching it with https://code.jquery.com/jquery-3.7.1.slim.min.js
Gmod doesn't appear to be using any comment directives or css class directives. Disabling them reduces the amount of processing AngularJS has to do.
CEF doesn't need this override. CEF accepts the updated CSS as the solution.
The game triggers 'languagechanged' once for every string that exists, nuking the translation cache each time even though the language only changes the first time. This fix makes it only do it once per language change.
Only update the translated text when the element doesn't have the value.

Additionally, only apply a value to the 'placeholder' attribute if the element supports the 'placeholder' attribute (ie input elements)
When a scope performs a digest, it also digests all descendent scopes. Gmod currently still calls them anyway.

This fix reduces identical digest duplication by checking if a parent scope is already going to be handling it or not.
Favourite checking: AngularJS looks at the 'IsFavMap' function for every single map multiple times every single click in the menu, with the function looping over the entire map list to check if the map name is in the favourites category. Instead, just add the favourite maps into a simple list on initial import and let it do a simple check there.

Icon: Just use a 'favmap' class and hover state instead of multiple classes
Clean up the logic for selecting the default category, and use the currently selected one if one is already selected. Don't ask the game for the last map if we've already got it set. Optimise logic for setting the last map to reduce redundant digests.
The reason "Start New Game" would freeze is because Gmod makes requests for 'asset://mapimage/' images for every single map even though the images shouldn't be getting requested for maps that are not being rendered. lazy loading wasn't working.
Instead of returning a dummy image I've swapped it to a CSS background-image. This causes the game to only request thumbnails that are actually on-screen. In theory this also means if you've got 1000 maps in a category but only 50 fit on screen before scroll, it'll only request 50 and gradually request the rest as you scroll, instead of requesting all 1000 from the category.

Additionally changed the category ng-repeat from using a ng-hide/ng-show combo to using ng-if. When using ng-hide/ng-show, Angular repeatedly processes the contents of categories that are hidden. With ng-if, it only processes the active category and its maps.
Don't need digest as the property change itself propagates.

ng-bind is the wrong method for this, changed to ng-change.

Simplify the friendsonly disable state logic. It should be disabled based on the p2p check not being checked.
Swapping certain elements from "ng-show"/"ng-hide" to "ng-if". Should reduce CPU load slightly.

Removed redundant UpdateDigest.

Increased the server insertion batch processing from 50ms to 100ms which shouldn't be noticeable visually but reduce the load of repeatedly looping over every single server every xms.
Addon list: small optimisations.

Addon list workshop files: Make use of the optimised UpdateDigest system.

Save/Dupe tabs in spawn menu: Keep the special handling for menu resizing (also used on first load), but prevent it from being cancelled by the optimised UpdateDigest.
@robotboy655 robotboy655 added the Enhancement The pull request enhances current functionality. label Oct 8, 2025
@DarthTealc
Copy link
Contributor Author

DarthTealc commented Oct 21, 2025

Split into individual PRs, including #2374 #2376 #2377 #2378 #2379 #2380 #2381 #2382 #2383 #2384 #2385

Not worth splitting: 71c4369

@DarthTealc DarthTealc closed this Oct 27, 2025
@DarthTealc DarthTealc deleted the angularoptimise branch October 28, 2025 10:48
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.

2 participants