FormularSumo / Star-Wars-Galaxy-Collection

A remake of the discontinued Star Wars Force Collection game https://formularsumo.github.io/Star-Wars-Galaxy-Collection-Web/ https://play.google.com/store/apps/details?id=com.formularsumo.starwarsforcecollectionremake.embed
GNU Affero General Public License v3.0
6 stars 0 forks source link

Performance improvements #35

Closed FormularSumo closed 3 years ago

FormularSumo commented 3 years ago

On my PC and laptop performance is perfect. Locked 144/60 FPS respectively. On smartphones not so much. On my phone (Pixel 4a, SD 730g) it gets 60 FPS in main menu, deck editor and battles with picture backgrounds but battles with video backgrounds (ie maxed dark side deck at the moment) it gets around 50. On my dad's Nokia 6 (SD430) FPS ranges from 11-15 and on my mum's P20 Lite (Kirin 659) 8-12 FPS.

Part of this may be because LuaJIT is disabled on Android (due to a bug) which slows things down a bit but most of it I think is due to the GPUs in our phones being a lot weaker than the ones in my PC/laptop, while the CPUs are much closer in performance.

Geekbench https://docs.google.com/spreadsheets/d/132oNpM9Te9dlcQXjsTGNivTSjlxMA7JS3Sc6F2RpdMs/edit?usp=sharing For example on my PC the game utilises about 10% GPU but only 0.5-10% CPU while on my laptop it's around 30% GPU and 2-20% CPU (task manager). On my phone CPU usage is also quite low, around 5-15% (Android Studio profiler). I can't easily see GPU usage on my phone but based on how powerful it is in relation to my laptop I can estimate it: (3981 / 1066 x 30%) = 112%. Obviously 112% GPU usage isn't possible, which would explain why my phone is dropping frames to around 54 (which would be about 101% usage (within margin of error)). My dad's phone's GPU is around 18% as powerful: 18% * 54 = ~10 FPS, which is roughly what I'm seeing.

I tried optimising some battle code, partially as I've been wanting to for a while https://github.com/FormularSumo/Star-Wars-Force-Collection-Remake/commit/77493368ec53a55fae6cda775b2e952932463151 https://github.com/FormularSumo/Star-Wars-Force-Collection-Remake/commit/1c7f4d756ec3305617554c4e12e2c1bf061e62ae https://github.com/FormularSumo/Star-Wars-Force-Collection-Remake/commit/6a4e10bc30ffba888b992066fda48fb6e0680204 https://github.com/FormularSumo/Star-Wars-Force-Collection-Remake/commit/948671305fadbbe6b19b0c9244269686a4b5f159 Unfortunately that didn't really improve FPS. Logic code happens on the CPU, so that was to be expected. CPU usage has gone down a little I think, but it's barely noticeable. Most the CPU usage comes from the game engine, providing frames for the GPU and similar, not from my battle code. If I want to improve performance on lower-end devices I'll have to figure out a way of reducing GPU usage.

https://github.com/FormularSumo/Star-Wars-Force-Collection-Remake/commit/41b68c512729f414f6719794bae30b4bf47f3f2c https://love2d.org/wiki/Canvas https://love2d.org/wiki/love.graphics.setBlendMode https://love2d.org/wiki/BlendMode https://love2d.org/wiki/love.graphics.clear I tried using canvases to achieve this, but (at least with my current implementation) performance has actually decreased a little, so I pushed this commit to a different branch.

FormularSumo commented 3 years ago

I tried running a few tests on my dad's phone to try and pin down what was impacting performance:

So I thought maybe the problem not to do with my character and background drawing and there was something else causing the performance drop. The only difference between my game with a background drawing and a blank project with a background drawing is that my game uses push.lua to scale the game to different resolutions.

Looking through the push.lua documentation I tried toggling the flags you can set when creating a window image One of them, canvas, turned out to be impacting performance massively. I had previously noticed by using love.graphics.getState() that 3 canvases were being used by my game, while I wasn't creating any. Disabling canvas flag causes 0 canvases to be used, and causes performance to improve massively. On my PC and laptop GPU usage has fallen and on my phone, my dad's phone and my mum's phone FPS is now locked at 60. I don't know what difference other than performance disabling canvas makes, but everything seems to be working the same. Considering I don't use canvases at all that's to be expected I think. https://github.com/FormularSumo/Star-Wars-Force-Collection-Remake/commit/9b6ab665d7cc824e110568c438e43caaa680a223