ChristopherKlay / StadiaEnhanced

Various new features for Google Stadia
GNU General Public License v3.0
261 stars 31 forks source link

Performance impact of using a loop #30

Closed ELowry closed 3 years ago

ELowry commented 3 years ago

Hi there,

I was going through your code while working on #29 and I noticed that a lot of your code uses one recurring loop, which can end up having quite an impact on performance, especially with stuff like the games filtering (which loops through all the games each time).

I know completely redoing the code to avoid this loop is not necessarily a good option at this point, but you could also try keeping it cleaner by simply checking if a setting has been changed before each "section" of the loop.

I'll use the 3 main parts that make up the filtering system as an example:

  1. For the main menu setting, I would simply set a variable enhanced_filterOption_modified to true whenever it is clicked.
  2. For the enhanced_showAll button, I'd do the same by setting a variable enhanced_filterShowAll_modified to true whenever it is clicked.
  3. Then for individual filter buttons, I'd add the game ID to an array enhanced_filterGame_modifiedList when it is clicked.

-> Then at the start of the relevant section of the loop, you can simply check if(enhanced_filterOption_modified == true || enhanced_filterShowAll_modified == true || enhanced_filterGame_modifiedList.length > 0) to if it needs to be run.

-> Then when looping through each game, you can simply ignore games that aren't present in the list.

Of course, it would be "cleaner" to have the resulting actions tied to each individual button instead of using a loop. But that would require some major overhauling.

ChristopherKlay commented 3 years ago

The issue and also the reason why i use a loop in the first place here is actually that simply dropping parts of the loop when nothing changes on my side (i.e. games are filtered already) doesn't work, due to things still changing on Stadias side.

Item filtering while searching is actually a good example for that. Once i filter out the items by looping through all of them and hiding unrelevant ones, Stadia actually pops in and simply completely reloads the entire list, including the old settings for visibility, multiple times.

The very same applies to games on the homescreen, which are not only re-added from Stadias side up to like 3+ times for some reason (i.e. a games icon loads in, gets completely removed and then just loads in again..) when you load the page, but they also don't unload when you for example load the store; they just stay hidden in the background and once you visit the homescreen again, instead of loading the old ones, Stadia again loads a new version on top of the old ones.

A lot of the loop is there (especially the "re-add" parts) to simply add things back in, that Stadia drops due to this whole mess of reloads, but most of the loop also isn't active most of the time, with pretty much no point where all can be active to begin with.

I do have to be careful, but right now even on a search page (afaik heaviest filtering), the loop only takes ~6ms on a 4-5 years old chromebook i have for testing those things.

ELowry commented 3 years ago

Ah, that does make sense!

Thanks for the clarification.