+ 1

Questions about how to improve performance of my code

I am using requestAnimationFrame to repeatedly run a function, and inside that function I make a lot of function calls, so that things are organized, is that bad for performance? Should I write everything directly inside the animation function instead so that it doesn't have to look for the functions? Also, is using canvas save() and restore() methods a lot also effecting the performance? Should I just change all the style properties of the canvas myself? Lastly, is it bad that I have added two different touch events to the window? I created one that runs a code for the joysticks and I added another touch event later that checks wether some buttons have been clicked or not, is this bad for the performance? Should I merge the code into only one event listener?

27th Apr 2021, 2:07 PM
Karak10
Karak10 - avatar
1 Antwort
+ 2
(Not very related to the question, but still.) IMHO, those things that you mentioned won't affect the performance of the code that bad. What's more important is the efficiency of your algorithm(like less memory space and cpu time consumption). Again, IMHO, focus more on making the code clever, clean and easy to understand and that what matters the most. Writing a very sweet syntaxical code is like adding extra cream to your cake. (which is good if you can effort) edit: I'm no canvas expert so I maybe wrong somewhere.
27th Apr 2021, 2:21 PM
RKK
RKK - avatar