I'm currently working on a CHIP-8 emulator. This platform requires me to draw 64x32 black/white pixels, ideally at a speed between 30 and 60 frames per second. There's an extension to it that increases the possible resolution to 128x64 black/white pixels. At this speed I've found it necessary to avoid needless consing, this severely limits my options. My experiences so far:

  • Generating SVG on the fly. My preferred library for this keeps creating tons of lists. The alternative would be using a template string, however I'm afraid editing it will create new strings, creating a comparable amount of garbage in the process.
  • Inserting lines of colored text, then moving across them and deleting/inserting differently colored text if needed. This is my current approach. It works fast enough at 64x32 pixels, but turned out to be too slow at 128x64 pixels. I can imagine that changing the properties of text might help, but haven't tested it yet.
  • Inserting a XBM image backed by a bool vector, then changing the bool vector's contents and forcing Emacs to redraw the image. The latter part is particularly painful as you need to (force-window-update BUFFER) and (image-flush SPEC) to make changes happen. Furthermore, not all changes are visible for a yet to be determined reason, the overall experience isn't nearly as smooth as with the previous solution. If drawn at a scale comparable to the text solution, the speed is in fact a bit worse. I've yet to test it at 128x64 pixels.

Are there any other possible solutions or tweaks I've overlooked? I'd prefer to stay within the options of vanilla Emacs before venturing into creating my own C module for creating a canvas I can quickly paint to...


Well, this was embarassing. It turned out that putting text properties is way faster than deleting and inserting text. Other answers and suggestions are still welcome though :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.