<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yooo, Games!</title>
    <description>The latest articles on DEV Community by Yooo, Games! (@pavel_kleschenok_6548f96a).</description>
    <link>https://dev.to/pavel_kleschenok_6548f96a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4248032%2Ff3269d4b-aea6-462c-a935-fcbbd7c143dc.png</url>
      <title>DEV Community: Yooo, Games!</title>
      <link>https://dev.to/pavel_kleschenok_6548f96a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pavel_kleschenok_6548f96a"/>
    <language>en</language>
    <item>
      <title>Offline phone games the server can still trust: we replay every game on the backend</title>
      <dc:creator>Yooo, Games!</dc:creator>
      <pubDate>Fri, 20 Nov 2026 15:12:38 +0000</pubDate>
      <link>https://dev.to/pavel_kleschenok_6548f96a/offline-phone-games-the-server-can-still-trust-we-replay-every-game-on-the-backend-2oem</link>
      <guid>https://dev.to/pavel_kleschenok_6548f96a/offline-phone-games-the-server-can-still-trust-we-replay-every-game-on-the-backend-2oem</guid>
      <description>&lt;p&gt;Last time I wrote about &lt;a href="https://dev.to/pavel_kleschenok_6548f96a/making-3d-bowling-run-on-a-2019-tv-browser-chromium-79-phones-as-controllers-3b1p"&gt;making 3D bowling run in a 2019 TV browser&lt;/a&gt;. That's the main product: a TV is the screen, and everyone's phone is the controller.&lt;/p&gt;

&lt;p&gt;Then I looked at who actually shows up from a game portal. One person came back four days in a row and played about nine full games of bowling. They never connected a second phone. They opened the &lt;em&gt;TV screen&lt;/em&gt; on their phone and threw the ball with a finger.&lt;/p&gt;

&lt;p&gt;People want to play alone, on the phone, right now. So we built a second part of the site: &lt;a href="https://yooo.games/play/?ref=devto2" rel="noopener noreferrer"&gt;yooo.games/play&lt;/a&gt;. It has seven small one-hand games: a bridge builder, falling blocks on a seesaw, a parking jam, a space merge puzzle, a minesweeper-like attic, a solitaire and a colour-burning puzzle. They're made to work on the subway, with no signal.&lt;/p&gt;

&lt;p&gt;![Seven one-hand games: build a bridge, balance blocks on a scale, free a parking lot, merge planets, sneak through an attic, solitaire]&lt;/p&gt;

&lt;p&gt;The games were the easy part again. The hard part was this: &lt;strong&gt;the game runs offline on the phone, but coins, stars and leaderboards live on the server.&lt;/strong&gt; How does the server know a score is real?&lt;/p&gt;

&lt;h2&gt;
  
  
  The rule: send the input, not the result
&lt;/h2&gt;

&lt;p&gt;The client never sends "I scored 2,480". It sends the smallest thing that &lt;em&gt;determines&lt;/em&gt; the game, and the server plays the whole game again.&lt;/p&gt;

&lt;p&gt;What that "record" is depends on the game:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Game&lt;/th&gt;
&lt;th&gt;What the phone sends&lt;/th&gt;
&lt;th&gt;What the server does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bridge builder&lt;/td&gt;
&lt;td&gt;The bridge itself: a list of beams&lt;/td&gt;
&lt;td&gt;Rebuilds it and runs the herd across, step by step&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Falling blocks on a scale&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;{ seed, moves }&lt;/code&gt;, one integer per move (&lt;code&gt;rotation ? 10 + column&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Deals the same pieces from the seed and replays every drop&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Parking jam&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;{ taps }&lt;/code&gt;, the cars in the order they left&lt;/td&gt;
&lt;td&gt;Builds the lot from the level's seed and replays the taps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space merge&lt;/td&gt;
&lt;td&gt;Aim points on a ±64 grid, not angles&lt;/td&gt;
&lt;td&gt;Replays every throw through the same physics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Solitaire&lt;/td&gt;
&lt;td&gt;Seed + moves&lt;/td&gt;
&lt;td&gt;Checks the seed is one of 1,000 known solvable deals, then replays&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If the replay doesn't reach the same end, the submit is rejected. If it does, the server computes the score &lt;em&gt;itself&lt;/em&gt;. The client's idea of the score is only used offline, to show you something before the server answers.&lt;/p&gt;

&lt;p&gt;This also makes every game tiny to store: a bridge is a few dozen numbers, and a falling-blocks game is one integer per piece.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hard part: the replay must match bit for bit
&lt;/h2&gt;

&lt;p&gt;The phone runs the game in Safari or Chrome. The server replays it in Node. A bridge that holds on an iPhone and collapses on the server would be a disaster. So would a merge that happens on one side and not the other.&lt;/p&gt;

&lt;p&gt;JavaScript gives you one good guarantee here. &lt;code&gt;+ ? ? ?&lt;/code&gt; and &lt;code&gt;Math.sqrt&lt;/code&gt; are exactly specified by IEEE 754, so every engine gets the same bits. &lt;code&gt;Math.sin&lt;/code&gt;, &lt;code&gt;Math.cos&lt;/code&gt;, &lt;code&gt;Math.pow&lt;/code&gt;, &lt;code&gt;Math.exp&lt;/code&gt; and friends are only "implementation-approximated" by the spec. V8 and JavaScriptCore can differ in the last bit, and in a physics loop the last bit grows.&lt;/p&gt;

&lt;p&gt;So the simulation code (the part shared by phone and server) follows a few rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only &lt;code&gt;+ ? ? ?&lt;/code&gt; and &lt;code&gt;Math.sqrt&lt;/code&gt;.&lt;/strong&gt; No trig, no powers, no &lt;code&gt;Math.random&lt;/code&gt;. Drawing can use anything, but the simulation can't.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No angles in the record.&lt;/strong&gt; In the space merge game you aim by touching the screen. The move is stored as a point on an integer grid, and the direction comes from normalising that vector with &lt;code&gt;sqrt&lt;/code&gt;. Rotating the pile uses precomputed cos/sin constants instead of calling &lt;code&gt;Math.cos&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integers where possible.&lt;/strong&gt; The scale game has no floats at all: torque is &lt;code&gt;? weight ? arm&lt;/code&gt;, and tilt is that number divided by a step, rounded toward zero.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Iterate in array order, always.&lt;/strong&gt; Merges happen one at a time, restarting from the start of the list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixed time steps.&lt;/strong&gt; The merge game steps at 1/60 s no matter how fast the phone renders, and no record depends on real time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The bridge builder is the heaviest. Beams are springs between mass points, solved with XPBD and substeps, and the herd walks over it with feet that press on the deck. The outcome depends only on the bridge. That's why the record is just the bridge.&lt;/p&gt;

&lt;p&gt;![The bridge builder: four sheep crossing a two-beam bridge]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fodbtce6sb7yho2jij9mt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fodbtce6sb7yho2jij9mt.png" alt=" " width="780" height="1688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Seeds the server can check
&lt;/h3&gt;

&lt;p&gt;Random levels need seeds, and a seed is an attack surface: a player could keep rerolling for an easy deal. So:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the &lt;strong&gt;daily challenge&lt;/strong&gt; seed is derived from the UTC date, and the server checks it against the date in the submit;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;solitaire&lt;/strong&gt; only deals from a table of 1,000 seeds that a full solver proved solvable (out of 2,663 checked, about 13 minutes of search). A debug seed in the URL still plays, but the server won't accept that game;&lt;/li&gt;
&lt;li&gt;the &lt;strong&gt;attic&lt;/strong&gt; game has no table. When you tap your first cell, it tries up to 60 seeds until a careful bot can reach the boss without a single guess. That takes 0.3 ms on average, so the server simply repeats the same search when it checks the record.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What can't be verified: time
&lt;/h3&gt;

&lt;p&gt;The phone reports how long you played, and coins depend on it. That number can't be proven. The scale game caps it at 4 seconds per move in the record, so a 30-move game can't claim an hour. Rewards also go through a shared daily limit.&lt;/p&gt;

&lt;p&gt;Replays aren't free either. A bridge replay costs tens of milliseconds of CPU, so submits are limited to 40 a minute per address.&lt;/p&gt;

&lt;h2&gt;
  
  
  Offline: a queue that never lies
&lt;/h2&gt;

&lt;p&gt;Games end in tunnels, so results go into a queue in &lt;code&gt;localStorage&lt;/code&gt; and are sent when there's a network. The phone tries right away, again when the &lt;code&gt;online&lt;/code&gt; event fires, when the page becomes visible, and on the next launch.&lt;/p&gt;

&lt;p&gt;Two details mattered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Two results for the same level don't both wait.&lt;/strong&gt; If you beat level 5 twice in a tunnel, only the better one stays in the queue, with a counter of how many games it stands for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A 429 or a 5xx keeps the item. Any other answer drops it.&lt;/strong&gt; A rejected record will be rejected forever, and retrying it would just burn CPU on both sides.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The service worker that never installed
&lt;/h2&gt;

&lt;p&gt;The whole game, about 77 chunks, is cached by a service worker, so the page opens with no signal at all. Each build gets its own cache, and the install is all or nothing. A half-cached build never becomes active, and the phone stays on the previous complete one.&lt;/p&gt;

&lt;p&gt;On the first production day, offline mode simply didn't work. The service worker's file list included one chunk that wasn't in the build. It was added by another part of the site after I'd tested offline mode. Caching that one URL failed, so the whole install failed, and nothing on the page told anyone. Now the list is generated from the files actually written to disk.&lt;/p&gt;

&lt;p&gt;A second trap came later. &lt;strong&gt;Cache Storage is per origin, not per service worker.&lt;/strong&gt; The phone-controller app lives on the same origin, and its new deploy "cleaned up old caches"... which included the offline games' caches. Each service worker now deletes only caches with its own prefix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our own test invented eight players
&lt;/h2&gt;

&lt;p&gt;To test offline mode there's a script. It starts headless Chrome, waits for the service worker, cuts the network through CDP (&lt;code&gt;Network.emulateNetworkConditions&lt;/code&gt;), and plays every game to the end. I ran it against production after each deploy.&lt;/p&gt;

&lt;p&gt;A few days later the stats looked odd. &lt;strong&gt;Level 3 of the bridge game had 13 players who'd beaten it. Levels 1 and 2 had 5.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It was the script. Each run used a fresh Chrome profile, so it was a brand-new guest every time. It built a known-good bridge on level 3. That bridge was valid, so the server accepted it. Eight deploys meant eight fake players who started at level 3 and never came back. I'd almost made a product decision ("guests drop off after level 3") based on them.&lt;/p&gt;

&lt;p&gt;The fix is boring: in production, submits from headless browsers and known bots are now rejected before the replay runs. The lesson isn't boring. &lt;strong&gt;Every test you run against production is a user in your analytics.&lt;/strong&gt; Filter it, or tag it, before you look at funnels.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shipping the games inside someone else's page
&lt;/h2&gt;

&lt;p&gt;We also put one of these games on itch.io. It runs inside their page in an iframe from another site, and that broke three things I hadn't thought about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sign-in can't work at all.&lt;/strong&gt; Our session cookie is &lt;code&gt;SameSite=Lax&lt;/code&gt;, and a browser won't set it in a cross-site iframe. Inside a foreign frame, "Sign in" now opens the same game in a new tab, where it works.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A query parameter clash.&lt;/strong&gt; The bridge game had a debug parameter, &lt;code&gt;?ref=3&lt;/code&gt;, that loaded a reference bridge. &lt;code&gt;?ref=&lt;/code&gt; is also how we tag traffic sources. So &lt;code&gt;?ref=itch-bridge&lt;/code&gt; would have turned on debug mode and crashed the page. I caught it before publishing, and the debug parameter is now &lt;code&gt;?tpl=&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The player couldn't close the help window.&lt;/strong&gt; In fullscreen on Android, the system shows "swipe down to exit fullscreen" at the bottom of the screen, and on some phones it stays until you swipe it away. It covered the "Got it" button. The window was also taller than a 640 px screen: &lt;code&gt;max-height: 100%&lt;/code&gt; doesn't limit a grid item in an &lt;code&gt;auto&lt;/code&gt; row. The fix was &lt;code&gt;grid-template-rows: minmax(0, 1fr)&lt;/code&gt;, &lt;code&gt;box-sizing: border-box&lt;/code&gt;, a sticky ? at the top, and closing the window when you tap outside it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;![Falling blocks on a seesaw: "Careful, it may fall!"]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffshaf4upaydh6hdkcun3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffshaf4upaydh6hdkcun3.png" alt=" " width="800" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell someone building this
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Send inputs, not results.&lt;/strong&gt; If the game is deterministic, the record is small, and the server's score is the only score.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ban non-deterministic math in the shared code, and write the rule down.&lt;/strong&gt; &lt;code&gt;+ ? ? ?&lt;/code&gt; and &lt;code&gt;sqrt&lt;/code&gt; only. Store aim as integers, not angles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never trust time.&lt;/strong&gt; Cap it by something you can verify, like the number of moves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make the service worker install all or nothing, and check offline mode on the production build&lt;/strong&gt;, not in dev.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your own scripts are users too.&lt;/strong&gt; Filter them out of production stats before you trust a funnel.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;You can play all seven at &lt;a href="https://yooo.games/play/?ref=devto2" rel="noopener noreferrer"&gt;yooo.games/play&lt;/a&gt;, on a phone or a laptop, with no sign-up. They keep working if you switch Wi-Fi off. If you have friends and a TV, the &lt;a href="https://yooo.games/r/devto2" rel="noopener noreferrer"&gt;party games&lt;/a&gt; are the main thing. I'd love to hear where the bridge physics breaks.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Part of the code, and the first draft of this post, were written with an AI assistant (Claude). The bugs, the fake players and the subway rides are real.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>webdev</category>
      <category>showdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Making 3D bowling run on a 2019 TV browser (Chromium 79, phones as controllers)</title>
      <dc:creator>Yooo, Games!</dc:creator>
      <pubDate>Tue, 17 Nov 2026 15:51:22 +0000</pubDate>
      <link>https://dev.to/pavel_kleschenok_6548f96a/making-3d-bowling-run-on-a-2019-tv-browser-chromium-79-phones-as-controllers-3b1p</link>
      <guid>https://dev.to/pavel_kleschenok_6548f96a/making-3d-bowling-run-on-a-2019-tv-browser-chromium-79-phones-as-controllers-3b1p</guid>
      <description>&lt;p&gt;Friends are over, dinner's done, and someone says "let's play something." Half the room doesn't know the board game. Nobody has a console. But everybody has a phone, and there's a TV on the wall.&lt;/p&gt;

&lt;p&gt;So I built &lt;a href="https://yooo.games/r/devto" rel="noopener noreferrer"&gt;yooo.games&lt;/a&gt;: you open the site in the TV's browser, everyone scans a QR code, and their phone becomes the controller. There's nothing to install, and you don't need an account. It now has 23 games. Some you talk and draw in (Find the Spy, Mafia with the screen as the host, Quick Pencil), and in others you swing the phone like a real object: a bowling ball, a revolver in a holster, a fishing rod.&lt;/p&gt;

&lt;p&gt;How it works: open the site on a big screen, scan the QR code, play together&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F819rym18vmmgf1vnpghv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F819rym18vmmgf1vnpghv.png" alt=" " width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The games weren't the hard part. The TV was. This post is about that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The reference device: an LG with Chromium 79&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My test TV is an LG on webOS. Its browser is Chromium 79, from late 2019, on a weak ARM chip with a Mali GPU. So I set the build target to that device and kept it there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// vite.config&lt;/span&gt;
&lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'chrome79'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first versions of the 3D games stuttered and froze on it. The 2D games were worse. Here's what I found, in the order it hurt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. On this TV, Canvas 2D runs on the CPU and WebGL runs on the GPU&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I measured every game on the TV. The three.js games (golf, bowling, curling) ran at 49-59 fps. The full-screen Canvas 2D games ran at 7-32 fps. The shooting gallery, a pretty simple game, managed 8 fps.&lt;/p&gt;

&lt;p&gt;It's backwards from what you'd expect: the "simple" 2D games were the slow ones, because on this TV Canvas 2D is drawn by the CPU.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What fixed it:&lt;/strong&gt; I stopped drawing with Canvas 2D every frame. Each sprite is drawn with Canvas 2D &lt;em&gt;once&lt;/em&gt; into a "stamp", uploaded as a texture, and from then on a small WebGL layer only positions those textures. On a desktop the shooting gallery's frame went from 4.5 ms to 0.3 ms. On the TV it was still slow, though, for the reason in the next section. Six more games were moved over the same way.&lt;/p&gt;

&lt;p&gt;There's a catch, and it took a while to learn: &lt;strong&gt;a stamp that gets redrawn costs a CPU paint plus a texture upload again.&lt;/strong&gt; One game redrew its characters every 250 ms and their eyes every 120 ms, which came to 281 texture uploads in 15 seconds. Now anything that moves is a static stamp moved by a transform, and animations are a few pre-drawn frames, not redraws.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Many &lt;code&gt;bufferSubData&lt;/code&gt; calls per frame stall the Mali tiler&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After the move to WebGL, the shooting gallery &lt;em&gt;still&lt;/em&gt; ran at 6-10 fps on the TV. JS timings, long tasks and even &lt;code&gt;gl.finish()&lt;/code&gt; showed nothing wrong.&lt;/p&gt;

&lt;p&gt;The cause: I rewrote one vertex buffer dozens of times per frame with &lt;code&gt;bufferSubData&lt;/code&gt;. On a tiled GPU like Mali, the driver has to stop and copy the buffer when you overwrite data a pending draw still uses. None of that shows up in a JavaScript profiler.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What fixed it:&lt;/strong&gt; I upload all vertices for the frame once with &lt;code&gt;bufferData(..., STREAM_DRAW)&lt;/code&gt; and draw in pieces by offset. The shooting gallery went to &lt;strong&gt;58 fps&lt;/strong&gt;, with a 17 ms frame. Now there's a counter in every room's debug journal, "vertex uploads per frame", and 1-3 is normal.&lt;/p&gt;

&lt;p&gt;![Shooting gallery on an LG TV: 8 fps with Canvas 2D, 6-10 fps with WebGL and many bufferSubData calls, 58 fps with one upload per frame]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4qrpi6w5ngqxibrtodcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4qrpi6w5ngqxibrtodcw.png" alt=" " width="799" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Shaders compiled mid-round are a freeze&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;three.js compiles a shader the first time an object becomes visible. On a desktop you never notice. On the TV, the first bonus item in a round, the first new golf hole, or a laser sight that's hidden until you aim each caused a visible hitch, sometimes hundreds of milliseconds.&lt;/p&gt;

&lt;p&gt;Things that quietly compiled new shaders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;transparent double-sided materials picked a shader again every frame (&lt;code&gt;forceSinglePass&lt;/code&gt; fixed that: frame p95 went from 33 to 17 ms in my slowed-down test);&lt;/li&gt;
&lt;li&gt;removing the last material of a kind throws away its program, so the jelly shader was rebuilt at the start of every round;&lt;/li&gt;
&lt;li&gt;setting &lt;code&gt;material.map&lt;/code&gt; from &lt;code&gt;null&lt;/code&gt; to a texture is a &lt;em&gt;different&lt;/em&gt; shader, so give materials an empty texture up front;&lt;/li&gt;
&lt;li&gt;hidden objects aren't compiled until first shown, so call &lt;code&gt;renderer.compile(scene, camera)&lt;/code&gt; (it walks hidden objects too) when the scene is built, and &lt;code&gt;compileAsync&lt;/code&gt; for things built mid-match.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rule now: anything that can appear in a round is prepared at game start. That covers textures (&lt;code&gt;initTexture&lt;/code&gt;), shaders (compiled against a warm-up scene), and pooled meshes that get hidden and reused instead of being disposed and recreated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. The DOM over the canvas was most of the main thread&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Name tags over eight players, with only &lt;code&gt;transform&lt;/code&gt; changing, took a fifth of the main thread: style recalc, layers, compositing. On the TV the overlay was relaid 100-170 times a second. Changing a font size every frame was worse. One game went from &lt;strong&gt;19 to 54 fps&lt;/strong&gt; and from 714 to ~0 ms/s of long tasks after I stopped doing that.&lt;/p&gt;

&lt;p&gt;What I do now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;anything that moves every frame lives &lt;em&gt;in the scene&lt;/em&gt;: name tags are one canvas texture and one draw call, and 3D labels are &lt;code&gt;THREE.Sprite&lt;/code&gt;s with &lt;code&gt;sizeAttenuation: false&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;text is written only when it changed (&lt;code&gt;setText&lt;/code&gt; checks first), and that includes writing the same &lt;code&gt;className&lt;/code&gt; or &lt;code&gt;hidden&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;never read &lt;code&gt;offsetWidth&lt;/code&gt; to restart a CSS animation, because that forces a full layout mid-frame;&lt;/li&gt;
&lt;li&gt;never read &lt;code&gt;clientWidth&lt;/code&gt; in the render loop; a &lt;code&gt;ResizeObserver&lt;/code&gt; reports size instead;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;new Intl.NumberFormat()&lt;/code&gt; on every call cost one game 5 ms/s, so formatters are cached.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A sneaky one: the results screen with faces and medals was rebuilt on &lt;em&gt;every state update&lt;/em&gt; (a spectator joined, someone sent an emoji reaction). On the TV each rebuild was a 1-3 second task with &lt;strong&gt;zero lines of JS&lt;/strong&gt; in the profile, just the browser decoding and rasterizing every image again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Chromium 79 doesn't know half of modern CSS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The bundler lowers syntax, but CSS is on you. Chromium 79 has no &lt;code&gt;:has()&lt;/code&gt;, no &lt;code&gt;gap&lt;/code&gt; in flexbox (my drawing albums sat glued together on the TV), no &lt;code&gt;aspect-ratio&lt;/code&gt;, &lt;code&gt;:is()&lt;/code&gt;, &lt;code&gt;@container&lt;/code&gt;, &lt;code&gt;dvh&lt;/code&gt; or &lt;code&gt;color-mix()&lt;/code&gt;. CSS built in JS strings isn't touched by the minifier at all, and one &lt;code&gt;:focus-visible&lt;/code&gt; in a selector list drops the &lt;em&gt;whole rule&lt;/em&gt;, &lt;code&gt;:hover&lt;/code&gt; included.&lt;/p&gt;

&lt;p&gt;There's now a guard in the build report that scans everything shipped to the screen for features Chromium 79 doesn't have, and it fails the build.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing a TV without the TV&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Walking to the living room after every change doesn't scale to 23 games. So there's a &lt;code&gt;tvcheck&lt;/code&gt; script: headless Chrome with Canvas 2D acceleration off, &lt;strong&gt;CPU throttled Г—20&lt;/strong&gt;, the TV's exact window size, and the game playing itself with bots. It reports fps, frame p95, long tasks, and the same counters as the TV journal (draw calls, vertex and texture uploads per frame, new shaders, DOM rebuilds per second), each with the line of code that caused it.&lt;/p&gt;

&lt;p&gt;Its numbers aren't the TV's numbers. Chrome doesn't slow down the GPU, and some TV hitches never show up on a desktop even with a software GPU. But anything that's expensive under Г—20 is expensive on the TV too. So I compare traces before and after a change rather than chasing fps.&lt;/p&gt;

&lt;p&gt;And there's an even weaker tier. Some TVs in the wild have no WebGL 2, or run Chromium 38. Those get a "superlite" mode: only the games whose screen has no WebGL and draws only when something changes (quiz, spy, drawing games, Mafia). The rest are shown greyed out, with an honest "won't run on this TV".&lt;/p&gt;

&lt;h2&gt;
  
  
  The other half: phones that disagree about physics
&lt;/h2&gt;

&lt;p&gt;Bowling reads &lt;code&gt;devicemotion&lt;/code&gt; while you hold a button, and computes the throw the moment you let go.&lt;/p&gt;

&lt;p&gt;!A throw in yooo.games bowling: the ball rolls down the lane, then a spare&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc7tpwwi6gn1xehcf9w6b.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc7tpwwi6gn1xehcf9w6b.gif" alt=" " width="560" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some things I didn't expect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Gravity has the opposite sign on iOS and Android.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;rotationRate&lt;/code&gt; axes don't match their names: in practice &lt;code&gt;alpha&lt;/code&gt; is rotation around x, &lt;code&gt;beta&lt;/code&gt; around y, &lt;code&gt;gamma&lt;/code&gt; around z.&lt;/li&gt;
&lt;li&gt;"Which direction did I throw" can't be read as an angle to the screen, because the phone doesn't know where the TV is. Instead you calibrate a straight throw, and direction is the deviation from that swing axis.&lt;/li&gt;
&lt;li&gt;Some phones have a gyro that's noisy or missing. After three suspicious throws in a row, the game switches to accelerometer-only mode, with a sideways jolt for direction and a late release for loft.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of it was tuned by eye. There are 58 recorded real throws from Android phones and iPhones as test fixtures. The physics (Rapier, 120 Hz) runs on the server with no renderer, and a sweep script throws thousands of balls across a grid of speeds and spins. The screens only replay 30 snapshots a second, about 150 ms behind, so a weak TV never runs the physics, and a second screen in the room shows the same game.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I'd tell someone starting this&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Measure on the real device first.&lt;/strong&gt; Two of my early "TV fixes" were guesses, and they did nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assume the CPU is your bottleneck and the GPU is your friend&lt;/strong&gt;, then count uploads, not just draw calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nothing new in the middle of a round&lt;/strong&gt;: no textures, shaders, materials or DOM rebuilds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep a written list of rules&lt;/strong&gt; and check them with a script. I re-learned the same lesson for every new game until they were written down.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;!Quick Pencil: three players drew "fish" on their phones, the TV shows all three drawings&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs3vouat82phr9tg2mogi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs3vouat82phr9tg2mogi.jpg" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can try it on any TV, laptop or projector: &lt;a href="https://yooo.games/r/devto" rel="noopener noreferrer"&gt;yooo.games&lt;/a&gt;. Bowling works with one laptop and one phone. With friends, start with Find the Spy or Quick Pencil. I've only tested one TV model properly, so if you have a Samsung, an Android TV or anything else, I'd love to hear what breaks.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Part of the code, and the first draft of this post, were written with an AI assistant (Claude). The measurements, the TV and the living-room playtests are real.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
