# The Playdate's CPU is fast, but its 4KB instruction cache will punish your code

Original title: Dirty Optimization Secrets (C for Playdate)

> Hacker News story 49936017 · language: en · submitted 2026-10-02
> Web version: https://zeli.app/story/49936017
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 78 · by [ibobev](<https://news.ycombinator.com/user?id=ibobev>) · 💬 13
[original](<https://devforum.play.date/t/dirty-optimization-secrets-c-for-playdate/23011>) · [HN discussion](<https://news.ycombinator.com/item?id=49936017>)

## Summary

A developer shares hard-won optimization tricks for Playdate C programming, learned while building a full-speed Game Boy emulator. The key insight: the Playdate's CPU is fast but memory access is slow, and its tiny 4KB instruction cache means -Os can beat -O3. The post covers custom linker scripts, placing code and data in tightly-coupled memory, and fighting the 'performance lottery' caused by cache misalignment and branch prediction.

## Key quote

> The first thing I did to improve performance for gameboy emulation was to squeeze the 20 kb emulator core into just 2 kb by removing a giant switch table and expressing it using much less code with just a few branches. The behaviour was identical, but it was much faster as a result.

## HN discussion (13 comments)

### [boricj](<https://news.ycombinator.com/item?id=49953277>)

> That reminds me of some of the tricks I've used while tinkering with a voxel space rendering tech demo on the PlayStation.
>
> The quirks of that console for this is that the CPU takes a 6 cycle stall on any read from main RAM (it's not even stall-on-use) and doesn't have a data cache. That would make it a very poor fit for this, so I had to improvise a bunch of tricks to reclaim performance:
>
> \- Made all of my hot loop fit within one function, so that it fits entirely in the 4 KiB direct-mapped instruction cache (so less than 1024 instructions)
>
> \- Wrote a C++ template that can trampoline a function call into the 2 KiB scratchpad
>
> \- Used the rest of the scratchpad for a CLUT table because it doesn't stall on read
>
> \- Used the GTE to transform the N set of coordinates while the CPU stalls fetching the N+1 set of heightmap data
>
> \- Figured ways to abuse the GTE into transforming more points per instructions than it theoretically can, taking advantage of simplified formulas compared to real 3D projection
>
> \- Write the rectangle primitives straight to the GPU registers instead of going through a display list
>
> It's such an abuse of the PlayStation that PCSX-Redux and DuckStation disagree on its performance by up to a factor of two. I should finish it someday and see how it runs on real hardware...

### [mococa](<https://news.ycombinator.com/item?id=49954583>)

> Rembers me - https://graphics.stanford.edu/~seander/bithacks.html

### [nxobject](<https://news.ycombinator.com/item?id=49953468>)

> The tips about laying out and carefully segmenting code are a blast from the past!

---

## Cite

- Page: https://zeli.app/story/49936017
- Date: 2026-10-02
- Source: devforum.play.date (https://devforum.play.date/t/dirty-optimization-secrets-c-for-playdate/23011)
- Hacker News: https://news.ycombinator.com/item?id=49936017

## Other languages

- zh: https://zeli.app/zh/story/49936017 · markdown: https://zeli.app/zh/story/49936017.md
- ja: https://zeli.app/ja/story/49936017 · markdown: https://zeli.app/ja/story/49936017.md
- ko: https://zeli.app/ko/story/49936017 · markdown: https://zeli.app/ko/story/49936017.md
- de: https://zeli.app/de/story/49936017 · markdown: https://zeli.app/de/story/49936017.md
- es: https://zeli.app/es/story/49936017 · markdown: https://zeli.app/es/story/49936017.md
- ru: https://zeli.app/ru/story/49936017 · markdown: https://zeli.app/ru/story/49936017.md
