Skip to content

Instantly share code, notes, and snippets.

@jaames
Last active August 30, 2022 22:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaames/664dffb7574baaf36d056a866d4210ea to your computer and use it in GitHub Desktop.
Save jaames/664dffb7574baaf36d056a866d4210ea to your computer and use it in GitHub Desktop.
James' Playdate performance tips

General tips

  • For repeated expensive drawing options, such as drawing a rotated sprite or a large amount of text, it's a good idea to cache the result to an image once and draw that repeatedly instead.
  • Audio formats in order of decode speed, fastest to slowest: 16-bit pcm wav, 8-bit pcm wav, adpcm, mp3.
  • The Playdate's audio sample rate is 44100, but if you're experiencing lag when playing audio at that rate, you can try halving the rate to 22050.

C tips

  • The Playdate has a weak CPU but a comparatively generous amount of memory. Favour memory-based optimisation techniques, such as lookup tables.
  • Where possible, move branch statements outside of loops, even if it means duplicating the code for the loop. (probably applies to Lua too?)
  • If you need to parse a binary file, use playdate->file->seek to jump to the parts you need and playdate->file->read to only read the data you want. Try to avoid memcpy-ing the whole file to memory in one go.
  • If you're blitting to the frame buffer and need to apply a pattern, use the bitwise and operator to mask your frame buffer against a premade pattern table. It's also ever so slightly faster to operate on your framebuffer 32 bits at a time, if possible.
  • Avoid recursion, you will stack overflow very fast.
  • When you compile a device build, a file called Playnote_DEVICE will be created in your build directory. (TODO: check this is the case for all build setups?). This is an ELF file, so you can load it into a decompilation tool like Ghidra to see the low-level instructions that the compiler has generated for your code, and look for potential performance issues there.

Storage optimisation tips

  • If you import everything your game uses into main.lua, and you're not using playdate.file.load() or playdate.file.run(), it is safe to strip every .pdz file apart from main.pdz from your game's compiled pdx.
  • C gets built into different formats depending on if you're targeting the Playdate device or Playdate Simulator. If you don't care for Simulator compatibility, you can strip any .dll, .dylib, etc files from your device build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment