6

I use PyGame for creating games, but I noticed that the programs ran a lot slower on macOS than on my Raspberry Pi. My original solution was to install Ubuntu alongside macOS on my computer, and that worked. However, I would rather only have one operating system on my computer. Does anyone know why PyGame is so much slower on my mac when running macOS?

If it would help, I can send code. However, I have multiple PyGame programs and they all do the exact same thing, so I figured that it was most likely not the fault of the code, but I could be wrong.

Any help is appreciated, thanks.

P.S. When I say slower, I mean that it is running at about 30% of the speed on macOS than it would on Ubuntu.

CircuitSacul
  • 1,594
  • 12
  • 32
  • 1
    Is you pygame and/or SDL version the same on both platforms? How disparate is the hardware? – Kingsley May 20 '20 at 23:56
  • 2
    I'm ran ubuntu and macos on the same computer, ubuntu worked faster for pygame. Pygame was also faster on my ***raspberry pi*** than my MacBook. So the hardware on my mac is better yet pygame is slower. A lot slower. @Kingsley – CircuitSacul May 21 '20 at 17:05
  • 1
    This question is on Python 2.7, but should still work: https://stackoverflow.com/questions/31685936/pygame-application-runs-slower-on-mac-than-on-pc – shreyasm-dev Jun 16 '20 at 01:05
  • 1
    @GalaxyCat105 I tried both of those answers. I have pygame running on low resolution. Also, I completely removed the `clock.tick()` link from the program. Still had the same problem. – CircuitSacul Jun 16 '20 at 11:58
  • 1
    I don't know about the PyGame module, but Python works fine on my Mac. It might be a problem with the PyGame module. – shreyasm-dev Jun 16 '20 at 15:00
  • 1
    How many FPS you're getting on each platform? This might be an issue where you're not calculating movement with the elapsed time in place, just relying on the actual frames. If your game feels "slow" that might be the issue. – WoLfulus Jun 17 '20 at 13:34
  • 1
    Can you do some benchmarking and post the results here? That should give us an idea about where the bottleneck is – prithajnath Jun 17 '20 at 13:44
  • 1
    is display set to window or full screen? I couldn't get window to work on my Mac, it was slow and laggy. Setting to fullscreen solved the problem. I then tried pygame 2.0.0.dev6 and everything was working as it should on both Mac and windows. – James Jun 17 '20 at 18:27
  • 1
    @James I will try setting it to full screen, but that still doesn't solve the initial problem -- but thanks for the suggestion – CircuitSacul Jun 17 '20 at 19:58
  • 1
    @WoLfulus My fps is fine... The game is very smooth, however, the boxes move slower on my mac than on my raspberry pi. I have the same problem across multiple games in the same way. I even tried removing all sleep and clock.tick() statements, but it did not help. – CircuitSacul Jun 22 '20 at 14:38

3 Answers3

2

Pygame is based on the SDL library. It supports using various rendering backends, such as OpenGL and metal. According to this answer (and the comment), it seems that the metal renderer might perform poorly on mac. Sadly, according to this issue, it seems that in most versions of pygame, it uses metal as the SDL backend for mac, and provides no way to change that.

There is the pygame.OPENGL flag you could pass to pygame.display.set_mode(), but I'm not sure exactly how it would affect anything. It might be a good idea to play with the other flags listed here.

I'd recommend you to open an issue on pygame's official github repo with the necessary details. Also, as a workaround, you could clone pygame, change the default renderer on mac to OpenGL, compile, and see if it improves anything. You can use the issue I mentioned above to understand where you should start.

kmaork
  • 5,722
  • 2
  • 23
  • 40
  • Thank you, this is what I was looking for. It makes sense that it would be slower because of different renderers, especially since macOS isn't really geared towards games... What I can probably do is thread my game, so that it updates the screen less often than it updates player position, so the boxes will more at the same speed just at a lower fps. – CircuitSacul Jun 23 '20 at 00:12
1

Try running your game in full screen mode

pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
Shizzen83
  • 3,325
  • 3
  • 12
  • 32
omar-h-omar
  • 84
  • 1
  • 2
  • 11
  • Oddly enough this mostly worked for me, it went from an abyssmal 11 FPS or worse to 50 FPS – Simon Jul 25 '20 at 23:02
  • This works for me, but can you please explain why? And is there a way to get the speed of this to work in non-full screen mode? – Simon Jul 25 '20 at 23:25
  • 1
    Well from what i could find it seems like it’s an issue with how the game renders like the top comment mentioned mostly because of the mac’s screen resolution. However when the game is set to full screen i think it drops the resolution because nothing has to run other than the game so it performs better. Hope this explains it :) – omar-h-omar Jul 27 '20 at 00:13
  • I think so. I tried to set the game to run in low resolution mode but they seemed to have removed that setting in OSX Catalina :( – Simon Jul 29 '20 at 03:49
  • I just checked and it's still there. I am also running OSX Catalina. To find it you should right click the application you're trying to start then select 'Get Info'. Once the popup opens you should find an option for 'Lower Resolution Mode'. – omar-h-omar Jul 30 '20 at 11:04
  • That options doesn't show up for me. Unsure what OS settings i need to change to make it visible, but it's missing from the 'get info' screen when I click on the python executable running the game. – Simon Jul 31 '20 at 22:18
-1

MacOS is generally slower

Unless you can install a second RAM stick it will always be that way