Skip to content
Tech News
← Back to articles

Optimizing Lua string literals to save 400 bytes

read original more articles
Why This Matters

This article highlights the importance of optimizing Lua code to fit within strict storage constraints in embedded environments like ComputerCraft. By refining string literals, developers can significantly reduce code size, enabling more complex programs to run on limited hardware. These techniques are crucial for creating efficient, self-contained scripts that improve usability and expand possibilities for in-game programming and embedded systems.

Key Takeaways

Optimizing Lua string literals to save 400 bytes

July 2, 2026

This is a guest post by Yuki about some tricks we use for Lua code compression in our shared ComputerCraft pet project. I’ve written about how we adapted bzip2 for this purpose earlier; this story is an installment that takes place in the same context.

If you want to read more stuff from her, here’s an Atom feed and the blog.

Context

Me and my girlfriend have created a bunch of cool programs for CC: Tweaked. Programs for CC:T are written in Lua, and in-game computers have limited disk space. The unadjusted limits are 1 MB of disk space per computer (or turtle) and 125 KB of disk space on a diskette. I use SI prefixes for bytes. You should too!

Our programs exceed that. By a lot. At the time of writing, a concatenation of all the lua code in the repo alongside its documentation is slightly larger than 440 KB, which does not fit in a single floppy and is simply too large.

We have a solution to the size problem, however, and it’s compression. Our data is Lua code and text, mostly code, though, and there are compression algorithms that are simply the Best (in terms of output size and decompression speed).

One of our goals was to create a self-decompressing archive in the form of a single file, so that the installation is as simple as typing

wget https://cc.purplesyringa.moe/initrd.lua startup.lua

... continue reading