Frontend challenge: why phones got hot and how we fixed it
The first version of the Atom Reaction board looked great and made phones hot. Players noticed after ten minutes of play. This is how I found the cause and fixed it.
The symptom
The game drew the board on an HTML canvas. On a modern phone with a 120 Hz screen, the browser asked for a new frame 120 times a second, and the renderer happily redrew the entire board every time, even when nothing was moving. Every orb had a soft glow and a gradient, which are expensive to draw.
Measure first
Before changing anything I measured frame cost in a headless browser. A board with 73 orbs took 1.7 milliseconds per frame to draw. Not huge for one frame, but multiplied by 120 frames a second for an hour, it adds up to a phone that is warm to hold.
Fix 1: draw orbs once as sprites
Instead of calculating the gradient and glow for each orb on every frame, I draw each orb style once to a small hidden canvas, a sprite, and then copy it with a cheap image draw. That cut the cost per frame from 1.7 to 0.7 milliseconds, about two and a half times faster.
Fix 2: do not draw when nothing changes
The renderer now runs at about 30 frames a second while idle and 60 only while explosions are flying. Later I made it smarter still: it redraws only when something actually changed, drops to a very low rate after 30 seconds of inactivity and shows a still picture once the game is over. On a 120 Hz phone this is about ten times less drawing work.
Fix 3: lite mode for older devices
Some phones are simply slow. The game now switches to a lite mode automatically on devices with four or fewer cores, two gigabytes of memory or less, data saver enabled or reduced motion requested, and also when it notices the screen is dropping frames. Players can override this in Settings with Auto, Lite or Full.
Fix 4: quieter sound and effects
The audio system was keeping the phone's audio hardware awake. It now suspends after three seconds of silence. I also removed a blurred backdrop on dialog windows, which was surprisingly costly on low-end devices.
What I measured afterwards
On a laptop test, the main thread usage while idle fell from about 20 percent to under 7 percent in lite mode, and memory stayed flat over a long run. I was careful to note that I could not measure on every real phone, so I kept the settings adjustable instead of promising one number.
More Atom Reaction guides
- How to play: The complete rules, critical mass numbers and a worked example of a chain reaction.
- Strategy guide: Ten practical tips for the opening, middle game, endgame and Battle Royale.
- Game modes: Online rooms, bots, pass and play, daily puzzle and Battle Royale explained.
- FAQ: Quick answers about players, bots, accounts and installing the game.
- Opening moves: Where to place your first orbs and what to avoid in the first five turns.
- Corner strategy in Atom Reaction: Why corners are the strongest cells and how to build chains out of them.
- Common Atom Reaction mistakes: Seven mistakes that cost new players games, with a fix for each.
- Beating the Atom Reaction bots: How each bot level thinks and the habits that beat them.
- Multiplayer tactics for Atom Reaction: Target selection, kingmaking and surviving a crowded board.
- Battle Royale survival guide: How the shrinking board works and how to be the last one standing.
- Two player strategy for Atom Reaction: Tempo, forcing exchanges and corner control in head-to-head games.
- Reading the board in Atom Reaction: A simple scan routine to spot threats and chains before they happen.
- Trap patterns in Atom Reaction: The decoy corner, the delayed fuse and the forced capture.
- Endgame guide: Count orbs, keep reserve moves and finish the last opponent.
- Choosing the right board size: How the grid size changes pace, tactics and player count.
- Reviewing your games to improve: Using replay and post-game review to find the move that lost the game.
- Hosting a game night: Rooms, invite links, spectators, chat and keeping everyone engaged.
- Playing on your phone: Install it, switch on lite mode and get turn alerts on any phone.
- How the Atom Reaction backend was built: FastAPI, WebSockets, in-memory rooms and a chain-resolving game engine.
- Backend challenges we faced and how we fixed them: Endless chains, room floods, rate limits and server hardening.
- Making multiplayer reliable: reconnects and dropped connections: Automatic reconnect, seat recovery and bots that cover for dropped players.
- How the Atom Reaction bots were built: Alpha-beta search, web workers and the experiments that surprised us.
- Saving games to a database without slowing play: A sleeping PostgreSQL database, background queues and privacy purges.