Pygame's Performance - What You Need to Know

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Summary: now with pygame 2.0 it's speed has significantly increased but before that it was quite slow. However, it is usually slow because of bad code written by newbies but that can be fixed (like using .convert() on images but that's less important in pygame 2.0).

πŸ‘οΈŽ︎ 5 πŸ‘€οΈŽ︎ u/Splorgamus πŸ“…οΈŽ︎ Aug 01 2021 πŸ—«︎ replies

As long as the flip() command takes longer than a millisecond on a fast pc I don’t think pygame is still fast enough for most large projects. It’s fine for anyone targeting 30 fps, but 60 and above will just need quit some optimisation.

πŸ‘οΈŽ︎ 1 πŸ‘€οΈŽ︎ u/Next-Adhesiveness237 πŸ“…οΈŽ︎ Aug 01 2021 πŸ—«︎ replies
Captions
a lot of people say the pie game is slow and that's because it is however there's more to that story than there seems and pygame is honestly a good fit for more types of projects than people generally think paige's reputation for being slow partially comes from its wide use for education and beginner projects so pie games performance is often portrayed as worse than it actually is because of the poor code written by beginners it also gets a bad rep graphically for similar reasons if you're watching this video shortly after it comes out you probably know who i am but i suspect this video will get some traffic far into the future from people researching the subject on their own rather than youtube recommending the video to them for those who don't know who i am i'm the fluffy potato i've been making games using pie games since 2013 i have made two commercial projects with pie game and i'm working on a third my first two were released before i had the marketing power of this youtube channel and also when i was less skilled but i still managed to average around twenty dollars in earnings for every hour i put into making a commercial game which proves that pie game can be commercially viable in some cases needless to say i know what i'm talking about on the subject of finance performance and its impact on use in game development there are two parts contributing to pygame's supposedly poor performance that you should understand if you're working with pie game understanding this will allow you to better use pygame for what it's effective at the first part is that pie game itself is a wrapper for the sdl library or sdl2 in the case of pygame 2. the second part is what people believe to be the main issue which is that pie game is for python it's not actually as big of an issue as people seem to think there's kind of a misconception there but that'll make sense in a bit so sdl or simple direct media layer is pretty much just a library for dealing with video audio input etc sdl was widely used to make games in the past but it also served a broader purpose outside of just games i mentioned before that pi gaming is a wrapper for sdl that means that when you call function in pi game it normally goes and calls some stl functions that were written in c many python built-in functions and libraries operate this way such as opencv which is part of what i use for the avatar i use when i'm streaming everything i wrote for it is in python knowing that many libraries operate like this is actually how you get the most out of python in general not just pie game anytime you do something expensive in terms of processing power it's best to offload it to some built-in functions or libraries written in c when possible so if pi game is offloading much of the functionality to something written in c why is it slow well in short sdl only uses the cpu for rendering while most modern libraries and engines use hardware acceleration with the gpu stl2 has support for hardware accelerated rendering and that functionality is partially implemented in pi game 2 but it's not documented yet it may be worth walking into if you're watching this video a couple years down the road i won't fully explain this as a million other sources for this subject but in short the gpu is much faster for rendering operations than the cpu so if the hardware accelerated rendering is so much faster then why would you want to use something like sdl in the first place well scl is easier to get into and generally quicker to write code for depending on what you're doing this is because working with the gpu takes some extra steps that require you to write code differently to get the most out of it since pi game is essentially a wrapper for sdl that's meant to be used with python it ends up being an extremely good library for educational purposes because of sdl's approachable rendering system and python's simplicity as a language however it's important to not just look at pie games used in education it's extremely effective for rapid game development assuming you've got a decent library of reusable scripts for certain systems like physics particles and entities if you're a solo developer like i am you can get stuff done very quickly see the 20-something game jams i've participated in with the stl discussion out of the way it's time to discuss the other thing affecting pie games performance many beginners that get into pie game for educational purposes will write bad code which hurts their performance when working with python you don't have as much room for mistakes compared to working with something like c plus plus if you design your code poorly in c plus you can get away with it for a while before the performance drops become too much of an issue in many cases for those who don't know languages like c or c plus are about 100 times faster than raw python when you strip out built-in functions and libraries written in other languages as mentioned before though pi games rendering functions are written in c so the way you structure your own stuff in python code is usually the bottleneck not the rendering writing good code with python is perfectly good enough for many types of games which is why i'm able to stick with python this may sound like a pain but in the end the development time with python is still significantly lower than using other languages in my opinion it's just a very different experience i don't have time to get into the details of all the different things you should be doing to get good performance in your games but ninety percent of the time the solution involves dictionaries i may make a series on it at some point though i've got two more crucial points to mention regarding the pie game's performance first off please remember to use dot convert on your images when you load them if you skip this step you're missing out on a 10x performance boost in some cases many newbies don't know that you need to do this and end up with super slow games as a result the second thing is that you should be using pygame 2 instead of pack game 1.9 point x nowadays pygm 2 is around 2 times faster than pie game 1.9 point x in many cases just keep in mind that the difference dramatically varies based on what you're doing just from these two points alone many beginners using pygame are getting around 1 20th of the performance they could be getting for raw rendering which is where a lot of pyke's bad reputation comes from so now you know the details of why pie game is considered slow and roughly what you can do about it but i know many people still want to double check if their game idea is doable in pi games since i get emails about it all the time making a game is a big project and you don't want to end up switching your library and language halfway through so i understand the concern you can make just about any 2d game with pie game although i specifically recommend pie game for pixar projects as you can get the most out of the cpu based visual effects when operating at a lower resolution that gets scaled the visuals are the main thing you need to be concerned about when determining if pi game is a good fit for your project the genre doesn't really matter so you can make platformers action games rpgs puzzle games etc while play game doesn't natively support networking that's not an issue if you want to make online games since you can use other libraries for sending data over networks it's actually pretty easy to make online games with pi game when you're working with other libraries another thing that pygame doesn't natively have support for that you don't want to be writing yourself is physics but if you want physics there are things like pie monk and box 2d that can be used with pie game for physics so as i stated before the main concern is just visuals those other elements you can just use other libraries mixed with pie game for here are a couple things i don't recommend doing in pi game the biggest one is any project where traditional shaders are necessary you can use shaders in pie game but you just end up using opengl if you're doing that and you don't use many of the normal stl bindings you may think that shaders are necessary to make the game look good but they definitely are not there are all sorts of cpu-based visual effects you can create obviously another thing i recommend avoiding pygm for is if you want to do anything in 3d while i've done it and i use it for the avatar i stream with pygame is not meant to be used for 3d projects there are plenty of other alternatives for that finally the last category i'd like to mention is any game where you want several layers of full resolution visuals i can get about 10 full layers at 1080p before i drop with 60fps which isn't ideal for some projects this is why i recommend pixel art when working with pygame you can use significantly more layers if implemented properly even though these things don't mix well with pie game that doesn't mean you can't use python for them people tend to overestimate the performance costs of game logic and you can definitely make 3d games or games with shaders using python take a look at things like pi opengl or cyano or relib if you're interested python could theoretically be used as a language for a game engine as well and i think it'd be a good fit the closest to actually doing it so far is godot which uses gd script which is pretty close to python that's the subject for another video though that's the core of my thoughts on this subject i can talk about it for hours given the opportunity and i've brought it up several times in my streams but i just wanted to mention the important stuff here please consider subscribing if you're interested in game dev with python as i'll likely be trying out things like our cyanide and right lib in the coming year i want that silver play button
Info
Channel: DaFluffyPotato
Views: 59,947
Rating: 4.9415016 out of 5
Keywords: DaFluffyPotato, gamedev, game development, programming, computer science, pygame, python, is pygame slow, pygame slow, pygame performacne, godot, ursina, pyopengl, opengl, python programming, pygame games
Id: hnKocNdF9-U
Channel Id: undefined
Length: 9min 10sec (550 seconds)
Published: Sat Jul 31 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.