-
Notifications
You must be signed in to change notification settings - Fork 827
AngularJS optimisation #2361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
AngularJS optimisation #2361
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
caad37a to
bdfbf26
Compare
Contributor
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.