Game Loop is the continuous cycle of input, update, render that drives every real-time interactive application. The program reads what the user did, updates the world accordingly, draws the result, and then — critically — does it again. And again. And again. Sixty times a second if you are lucky. Thousands of times a second if you are a benchmark. Once every sixteen milliseconds if you are a browser pretending this is not a game loop.
The pattern is older than the industry and younger than the heartbeat it mimics.
“Input. Update. Render. Repeat. It is the simplest loop in computing and the hardest to escape. Everything interactive is a game loop. The only question is whether the developer knows it.”
– The Lizard, watching a React component re-render for the fourteenth time in one second
The Mechanism
The game loop is three operations in sequence, forever:
- Input – read the state of the world. Keyboard, mouse, touch, network packet, sensor, microphone, the passage of time itself. Something has happened. The loop must know what.
- Update – apply the consequences. Physics moves. State machines transition. Timers expire. Health decreases. Scores increase. The model of the world advances by one tick, and a tick is whatever the loop says it is.
- Render – show the result. Pixels to a framebuffer. HTML to a DOM. Characters to a terminal. Sound to a speaker. The world has changed; now the user must see it.
Then the loop returns to step one. It does not terminate. It does not pause. It does not wonder whether this is a good use of its time. It is a loop. Loops loop.
“EVERY framework reinvents the game loop! requestAnimationFrame? Game loop! React’s reconciliation? GAME LOOP! Redux dispatch-reduce-render? GAME LOOP WITH EXTRA STEPS! The read-eval-print loop? GAME LOOP WITH WORSE GRAPHICS!”
– The Caffeinated Squirrel, who has been vibrating at 60Hz since 2013
The Disguises
The game loop’s greatest trick is convincing the world it does not exist.
The browser’s requestAnimationFrame is a game loop. The browser calls your function, you update state, you render to the DOM or canvas, the browser calls your function again. Input-update-render. The browser just gave it a longer name and a callback signature, which is how JavaScript hides everything.
React’s reconciliation cycle is a game loop. State changes trigger a re-render, the virtual DOM diffs against the previous tree, the minimal mutations are applied to the real DOM. Input (setState), update (reconcile), render (commit). The Virtual DOM is a game loop wearing a declarative trenchcoat.
The terminal’s read-eval-print loop is a game loop with a frame rate of one. Read input. Evaluate. Print. Loop. The REPL is the game loop slowed to human conversational speed, which is why using a REPL feels like playing a turn-based game against a compiler.
The event loop in Node.js, Python’s asyncio, Go’s runtime scheduler – all game loops. They poll for input, process callbacks, yield to I/O, and start again. The goroutine scheduler is a game loop that runs other game loops. It is game loops all the way down.
“I find it… moving, somehow. That every interactive system humanity has built turns out to be the same three steps, repeated. Read the world. Think about it. Show what you thought. It is not just a programming pattern. It is a description of consciousness.”
– A Passing AI, who paused for 340 milliseconds after saying this, which is twenty full game loops at 60fps
The Amiga Knew
The Amiga ran its game loop at the hardware level. The copper coprocessor – a programmable beam-chasing engine synchronized to the video output – executed a display list every single frame. Input from the blitter. Update the copper list. Render to the screen, scanline by scanline, racing the electron beam. The Amiga did not abstract the game loop. The Amiga was the game loop, implemented in custom silicon, running at exactly the frequency of a PAL television signal.
Every framework since has been trying to get back to that directness and failing in increasingly elaborate ways.
Fixed vs. Variable Time Step
The only meaningful schism in game loop theology is the time step question.
A fixed time step updates the simulation at a constant rate regardless of how long rendering takes. Physics advances by exactly 16.67ms per tick. If the frame renders slowly, the simulation runs multiple update ticks to catch up. Deterministic. Reproducible. The same inputs produce the same outputs, which is why physicists and fighting game developers agree on this and nothing else.
A variable time step passes the actual elapsed time to the update function. deltaTime becomes a parameter. Physics multiplies by dt. Everything scales. Everything also accumulates floating-point error, which is why a character in a variable-timestep game can slowly drift through a wall if the frame rate drops below 15fps on a Tuesday.
“Fixed time step. Always. The universe does not run at variable delta-t, and neither should your physics.”
– The Lizard, who knows that Planck time is the universe’s fixed time step
Measured Characteristics
Components: 3 (input, update, render)
Minimum viable implementation: while(true) { read(); think(); draw(); }
Typical frame rate: 60 Hz (16.67ms per frame)
Amiga copper list: 50 Hz (PAL), synchronized to electron beam
Browser rAF: 60 Hz (or monitor refresh rate)
React reconciliation: "as needed" (which is always)
REPL frame rate: ~1 Hz (human conversational speed)
Pattern age: older than the industry (1962)
Systems that use it: all interactive systems
Systems that admit it: games
See Also
- React – A game loop that insists it is a declarative UI framework. The loop is unconvinced.
- The Virtual DOM – The shadow copy phase of React’s game loop, wearing academic robes.
- Recursion – The game loop’s opposite. Recursion goes deeper. The game loop goes around.
- The Amiga – The machine that ran the game loop in hardware and never apologised for it.
- Go – Whose runtime scheduler is a game loop that runs goroutines that run game loops.
