Lua Memory Consumption Tips


As you develop it's always worth paying attention to your memory use. The Play.Date Simulator has a handy 'Show Lua Memory (Alt+M)' panel which shows you where Lua memory is going:


Looking at this today I learned two things!

1. WAV files are almost 1:1 between their file size, and when they are loaded into Lua memory on the device. This is why the Inside Play.Date SDK documentation clearly warns you about WAV files! That musicPlayer object is playing the Lone Fury title music - a 3.2MB file on disk. If you're using Audacity, you also want to export your WAV files as "IMA ADCPCM" which is the best, most compressed format the Play.Date supports according to the fine folks at the PlayDate Squad Discord server. Using IMA ADCPCM reduced that 3.2MB music file to 800kb. WAV files for music can also be streamed from the Play.Date filesystem using a fileplayer, rather than a sampleplayer which also saves memory.

2. Do NOT define Lua functions you are not going to use. I'm dragging in the lume.lua file in it's entirety but only using two functions from it! This also applies to test code as well. Considering removing it or commenting it out. For example I've just deleted the stateTest.lua file from LoneFury.

Get Lone Fury Arcade Shooter for play.date

Leave a comment

Log in with itch.io to leave a comment.