Triple Buffering
Chau7 rotates three buffers with atomic swaps. The parser and GPU never block each other. Zero tearing.
What is Triple Buffering in Chau7?
Triple Buffering in Chau7 is a rendering architecture that maintains three screen buffers rotated between the terminal parser and the Metal GPU renderer. Chau7's parser writes new terminal state into one buffer while the Metal renderer reads a different completed buffer. A third buffer sits ready as a spare.
When the parser finishes a frame, Chau7 performs an atomic index swap that makes the completed buffer available to the renderer and gives the parser a fresh buffer to fill. This lock-free design prevents both tearing and render stalls.
How Chau7 prevents screen tearing in terminal applications
Screen tearing happens when the renderer reads a buffer that the parser is still writing. The result is a frame that shows half-old and half-new content.
Chau7 eliminates this by maintaining three buffers in rotation. The parser always writes into a dedicated buffer. The renderer always reads from a separate completed buffer. Because there are three buffers, neither thread ever waits for the other, and the renderer always draws a complete, consistent frame.
The buffer rotation uses an atomic index swap with acquire-release memory ordering, plus data copying of dirty rows to the new buffer. There are no mutexes, no condition variables, and no possibility of priority inversion. The synchronization cost includes the atomic swap and any dirty row data copying needed to keep buffers consistent.
How does Chau7's triple buffering compare to other terminals?
Most terminal emulators use double buffering with mutex locks. When the GPU reads the buffer, the parser must wait. When the parser writes, the GPU must wait. This contention causes visible stalls during fast output.
Chau7 uses three buffers with atomic swaps instead of two buffers with locks. Chau7's parser and Metal renderer never block each other. The result is tear-free rendering at any output speed with no stalls and no frame drops.
Does Chau7's triple buffering increase memory usage significantly?
No. Each buffer in Chau7 holds the visible terminal grid, typically 80x24 to 240x80 cells. At roughly 40 bytes per cell (4B char + 16B fg + 16B bg + 4B flags), three buffers consume under 3 MB even for a large terminal.
The memory cost of Chau7's triple buffering is negligible compared to the performance benefit. Eliminating all mutex contention between parser and renderer is well worth a few megabytes of memory.
How does Chau7's triple buffering interact with ProMotion 120Hz displays?
Chau7's triple buffering is refresh-rate independent. On a 120Hz ProMotion display, the Metal renderer picks up the latest completed buffer 120 times per second. The parser continues writing at PTY speed regardless of the display refresh rate.
The extra buffer ensures Chau7's renderer always has a complete frame even at twice the standard swap rate. On 60Hz displays, Chau7's triple buffering works identically, just with fewer pickups per second.
Questions this answers
- What is Triple Buffering in Chau7 terminal?
- How does Chau7's triple buffering compare to other terminals?
- How to prevent screen tearing in terminal applications
- Does triple buffering increase memory usage significantly?
- How does triple buffering interact with ProMotion 120Hz displays?
Frequently asked questions
What is Triple Buffering in Chau7 terminal?
Triple Buffering in Chau7 is a rendering architecture that maintains three screen buffers rotated between the terminal parser and the Metal GPU renderer using atomic index swaps. Chau7's triple buffering prevents tearing and render stalls without any mutexes or locks.
How does Chau7's triple buffering compare to other terminals?
Most terminal emulators use double buffering with mutex locks, which causes the parser to stall while the GPU reads the buffer. Chau7 uses three buffers with atomic swaps, so the parser and GPU never block each other. This lock-free design eliminates both tearing and render stalls.
How to prevent screen tearing in terminal applications
Chau7 prevents screen tearing by maintaining three screen buffers rotated with atomic index swaps. The parser writes into one buffer while the Metal renderer reads a different completed buffer. Because there are three buffers, neither thread ever waits for the other, and the renderer always draws a complete frame.
Does triple buffering increase memory usage significantly?
No. Each buffer in Chau7 holds the visible terminal grid, typically 80x24 to 240x80 cells. At roughly 40 bytes per cell (4B char + 16B fg + 16B bg + 4B flags), three buffers consume under 3 MB even for a large terminal. The memory cost is negligible compared to the performance benefit.
How does triple buffering interact with ProMotion 120Hz displays?
Chau7's triple buffering is refresh-rate independent. On a 120Hz ProMotion display, the Metal renderer picks up the latest buffer 120 times per second. The parser continues writing at PTY speed regardless. The extra buffer ensures the renderer always has a complete frame even at twice the standard swap rate.
What happens if the parser produces frames faster than the display refresh?
Chau7's renderer always picks up the latest completed buffer at display refresh time. If the parser has produced multiple frames between refreshes, intermediate frames are skipped. This is the correct behavior because displaying stale intermediate frames would waste GPU time without visual benefit.