Quick Answer: JIT bitmap text rendering generates machine code for each specific string at run time. Glyph offsets, bit shifts, and widths become instruction operands instead of table lookups. On an RP2350, this keeps proportional text inside a racing-the-beam budget of roughly 6 cycles per pixel. In Raph Levien's vic-2350 renderer, the generated inner loop costs about 23 cycles per glyph.

Most microcontroller projects that draw text reach for a fixed character cell. It's easy, and it's fast. Proportional spacing looks better, but it usually adds per-glyph work on every line. Levien's vic-2350 project, a re-imagined 1980s home computer on an RP2350 board, took the harder path. His JIT bitmap text rendering approach makes proportional bitmap text fast enough to run inside a hard real-time video budget.

Why Bitmap Text Still Earns Its Place

Bitmap fonts have fallen out of favor, but at low resolutions they have a real advantage. Antialiasing a small font on a low-resolution display often produces what Levien calls "the blurry mush" of soft edges. A hand-designed bitmap stays crisp because every pixel was placed on purpose.

The history matters here. In the early 1980s, most home computers and terminals used a fixed cell size. Hardware looked up each character in a font ROM as the image was scanned out. That was fast and cheap, but it only supported monospace fonts. The alternative was a bitmap framebuffer, pioneered on the Xerox Alto, carried through the Apple Lisa, and made popular by the Macintosh. Framebuffers allowed proportional type but demanded far more computing power to keep updated.

Here's the common advice, and why it's incomplete: "Use a fixed cell on a microcontroller." That advice is correct for throughput, but it treats proportional spacing as inherently expensive. Levien's work shows the cost of proportional text is mostly a per-glyph lookup and shift. Once you precompute those values, the cost can drop to a few instructions per glyph.

So why not just use a fixed cell? Because you lose the typography. If you want the early Macintosh feel, you need proportional spacing and kerning.

Racing the Beam Leaves a Tiny Budget

The RP2350 can drive DVI through its HSTX peripheral, but software has to fill the video buffer. Levien has 520kB of SRAM to work with, which is not enough for a framebuffer at useful resolution and depth while leaving RAM for the app. So he races the beam instead, filling each scanline as it's scanned out.

That choice buys visual richness and low latency, but it sets a hard limit. Levien budgets about 6 cycles per pixel. Go over it and the picture tears or stutters. Stay under it and the leftover cycles go to sprites, other objects, and application logic.

The renderer runs as a pipeline:

  1. The application builds a display list of display objects. Building it can allocate, because the list size isn't known at compile time.
  2. At each vsync, if the app is ready, the display list is swapped with the one being scanned out.
  3. Object indices are sorted by their top edge (y0).
  4. For each scanline, the renderer keeps an active list of objects that cross that line, inserting and deleting objects as their edges are reached.
  5. For each active object, the renderer calls its start, render, and end methods.

Text is just another display object. Its payload is the string, one byte per character, plus a pointer to the font and two colors. That's a deliberate choice. An earlier version stored expanded text in the display list, and that created "unacceptable memory pressure" once the screen was full of text. Since the display list is double-buffered, every byte you store there is effectively paid for twice. When the screen fills with text, storing the raw string instead of the expanded form saves real RAM.

The text object's start method is where the interesting work happens. It allocates scratch space for the JIT code and a 1-bit-per-pixel intermediate buffer, then compiles the string into code. Its render method runs that code and then expands the 1bpp buffer into 16-bit RGB565 pixels.

Packing the Font So One Load Covers a Row

The font stays in SRAM. Levien notes that flash could cause stalls during video-rate rendering, so the packing has to be tight. His packer stores all glyph ink in one wide bitmap the same height as the font. Two details make the generated code fast.

First, no glyph straddles a 32-pixel chunk boundary. That means one row of any glyph can be read with a single 32-bit load. Second, the packer detects overlaps and shares pixels. Glyphs don't need unique pixels, and a glyph that sits inside another doesn't need its own copy. Levien's examples are surprising. The lowercase l is the left side of U, and 0 is () with the space between them removed. Packing this way shrinks the font bitmap from 1140 bytes to 960 bytes. He says every byte counts, and more so as fonts are added.

Per-glyph metadata fits in a single 32-bit integer. It has four conceptual fields:

  • The x position and width of the ink within the packed bitmap
  • The left-side bearing (space on the left, stored outside the bitmap)
  • The advance, the distance to the next glyph's origin

Kerning adjusts the advance. The bitmap doesn't need to change for it. That keeps the metadata small and the lookup cheap.

Most people stop here, but the packing is only half the story. The metadata has to turn into code, and that's where the JIT comes in.

Generating Machine Code for Each String

The generated code uses a fixed register contract. r0 points to the start of the packed font row. r1 is the output buffer, a one-line 1bpp image. r2 is the accumulator for the output word. r3 holds one glyph's bits, extracted from r4, which holds 32 bits loaded from the glyph bitmap.

The simplest case, adding one glyph that doesn't straddle the accumulator, looks like this:

ldr  r4, [r0, #(x_offset / 32 * 4)]
ubfx r3, r4, #(x_offset % 32), #(width)
orr  r2, r3, lsl #(x % 32)

Real output also needs a store when the accumulator fills (stmia r1!, {r2}) and a path for glyphs that straddle a 32-bit boundary. Levien documents those cases in text.sy.

The generator writes this code by patching instruction words. For each glyph, it looks up a ubfx encoding from a table indexed by bit offset, fills in the width, and writes the ldr offset into a slot. It also looks up the orr shift from a second table. Blank glyphs skip all of this.

There's one trick worth copying. The ubfx depends on the ldr result, and the core stalls for that delay. Levien moves the first instruction of glyph i+1 into the delay slot after glyph i's last instruction. That cuts the per-glyph cost from 4 cycles to 3 for that pair. It's the kind of change you only make after reading the disassembly.

Here's the cycle-annotated loop from Levien's symbolasm analysis, which he measured at 23 cycles per iteration. The K flags mark branches whose conditions resolve late, and the H flags mark 32-bit instructions forced by high registers.

What the Numbers Say

Levien's figures break the cost into separate terms. Here they are side by side.

Cost componentCycles (per source)What it scales with
Generated loop, per glyph23 cyclesNumber of glyphs
Bitmap generation, per glyph3 cycles × glyph heightGlyph height
Additional JIT costAbout 20 cyclesPer generated string
Output word writes2 cycles × height per 32 bitsOutput width
1bpp to RGB565 expansion1.75 cycles per pixelPixel count

The expansion pass matters most at steady state. At 1.75 cycles per pixel, it uses about 29% of the 6-cycle budget before anything else runs. That's a strong argument for keeping the 1bpp intermediate buffer small and simple. Each pixel costs little on its own, but full-screen text touches every pixel in the scanline.

The JIT overhead is not free, and it's not per pixel. Since it's paid once per string, the economics favor long-lived strings. Redrawing a changing string every frame means regenerating code every frame, which you should measure before committing to.

Trade-Offs, Caveats, and When to Skip This

This technique isn't a general answer. Levien's version works because the constraints are specific. Consider these points before you copy it.

First, you're writing ARM assembly, or at least generating it. Levien says Rust couldn't meet the budget, and he wrote the renderer in symbolasm, his language for high-performance Cortex-M33 code. That means you inherit a toolchain and a target architecture. Porting to Cortex-M0+ or RISC-V means rewriting the generator.

Second, the code and the 1bpp scratch buffer come from RAM. Both are allocated when the text object starts. When the screen is full of text, that memory is real, and the double-buffered display list makes it worse.

Third, the approach favors static text. A string that changes every frame pays the JIT cost every frame. Levien's design avoids storing expanded text in the display list for memory reasons, but it doesn't remove generation cost.

Fourth, this is not a fixed-cell replacement for every project. If your app only needs a terminal, a fixed cell with a font ROM is simpler and faster to build. If you want proportional type, kerning, and a framebuffer-free pipeline on constrained RAM, JIT bitmap text rendering is the stronger choice.

The technique also isn't limited to racing the beam. Levien says the same generation approach works when writing into a framebuffer. The bottleneck changes, but the packing and per-glyph codegen still apply.

Frequently Asked Questions

What is JIT bitmap text rendering?

JIT bitmap text rendering generates machine code for a specific string at run time. Each glyph's bitmap offset, bit extraction, and shift become instruction operands, so the renderer avoids per-glyph table lookups. Raph Levien uses it in the vic-2350 renderer on an RP2350 to draw proportional bitmap text inside a racing-the-beam budget.

How do you render proportional bitmap fonts on a microcontroller?

Pack all glyph ink into one bitmap with the same height as the font. Avoid straddling 32-pixel boundaries, so each row reads with one 32-bit load. Store per-glyph metadata (ink position, width, left bearing, advance) in a compact integer. Then generate code that extracts each glyph and combines it into an output line buffer.

Why does a JIT speed up text rendering on a microcontroller?

A JIT removes work that a generic renderer repeats for every glyph, such as looking up offsets and shifts. It bakes those values into instructions and can reorder them to hide load-use delays. In Levien's implementation, the generated loop costs 23 cycles per glyph, with a per-glyph reordering that cuts one pair from 4 cycles to 3.

Can JIT bitmap text rendering work with a framebuffer instead of racing the beam?

Yes. Levien notes that the same technique applies when writing into a framebuffer. The renderer changes, but the font packing and per-string code generation stay the same. Framebuffers are limited by RAM, so the 520kB SRAM on an RP2350 still forces trade-offs in resolution and color depth.

Race-the-beam rendering isn't the only way to get fast text on a small chip, but it forces you to measure every cycle. If you're building a display project, try generating code for one fixed string and count the cycles in your disassembly this week. Pass Levien's write-up to someone wrestling with text on a tight microcontroller budget. Their next step is the same one: count the cycles before you optimize.