steamutil: Optimise get_steam_app_list
#566
Open
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.
Overview
This PR makes some optimisations to
steamutil#get_steam_app_list. In my endeavours to see if there is anywhere the startup time for ProtonUp-Qt could be improved, I managed to discover a very small optimisation we can make.These tests were performed with Python 3.10.17 running in a virtual environment on endeavourOS on a Ryzen 3700X CPU.
Implementation
The main optimisation comes from avoiding repeated dictionary lookups. We lookup the same values inside of our loops, so instead we can store these values and re-use them so they aren't fetched multiple times.
Benchmarks
These tests were done using
time.perf_counter. The first commit keeps the timing in place, so you can check out this commit and benchmark independently.These tests were conducted on endeavourOS on a Ryzen 3700X CPU.
First Run
On a fresh boot of my PC before running
python3 -m pupgui2, execution takes significantly longer onmainand this PR. I have not included this figure at time of writing as I will need to reboot my PC to verify the speedup.mainSubsequent Run
I ran ProtonUp-Qt 10 times on this PR, and 10 times on
main.mainThe longest execution time on
mainwas 0.231s. The fastest time was 0.184s. The longest execution time on this PR was 0.176s. The fastest time was 0.137s. With this PR, no runs apart from the first run of ProtonUp-Qt took longer than 0.2s in my testing during development and also while benchmarking for this PR.Future Work
This is... a very minor speedup. But a speedup nonetheless! The main bottleneck from my tests is
update_steamapp_info. This is where the 3-4 second startup time comes from on my PC (and longer on handhelds like the Steam Deck). This is probably the "main" area for optimisation, but it isn't as straightforward as the speedups we have in this PR. So I recognise this PR is a small optimisation in the grand scheme, but I hope it can still be considered :-)As another anecdotal note, I did a test the other day with Python 3.13. It offers a significant speedup in overall execution speed including opening time, opening in about 2-3 seconds instead of 3-4 seconds on my machine. This is something else we can consider when applying updates. Anecdotally, Python 3.12 was slower in my test.
As always, all feedback is appreciated! I could be mistaken or naive with how I've tested the speedups too, so I'm very happy to discuss and give feedback.
Thanks!