<?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: Dmitrii Korotkin</title>
    <description>The latest articles on DEV Community by Dmitrii Korotkin (@dmitrii_korotkin).</description>
    <link>https://dev.to/dmitrii_korotkin</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%2F4184540%2F88dc07c2-ba28-4b9d-ad3a-49a45e990899.jpg</url>
      <title>DEV Community: Dmitrii Korotkin</title>
      <link>https://dev.to/dmitrii_korotkin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dmitrii_korotkin"/>
    <language>en</language>
    <item>
      <title>One clip-path doubled my browser cat's CPU cost in Chrome's GPU process</title>
      <dc:creator>Dmitrii Korotkin</dc:creator>
      <pubDate>Thu, 19 Nov 2026 23:37:20 +0000</pubDate>
      <link>https://dev.to/dmitrii_korotkin/one-clip-path-doubled-my-browser-cats-cpu-cost-in-chromes-gpu-process-3pdb</link>
      <guid>https://dev.to/dmitrii_korotkin/one-clip-path-doubled-my-browser-cats-cpu-cost-in-chromes-gpu-process-3pdb</guid>
      <description>&lt;p&gt;I made &lt;a href="https://tabloaf.dmitryq.com/" rel="noopener noreferrer"&gt;Tabloaf&lt;/a&gt;, a pixel cat for Chrome and Firefox. It walks across whatever page you have open, sits on pictures and headings, and chases a ball of yarn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR: while the cat walks, Chrome's GPU process went from 15–17% of a core to ~7%, and Firefox's page process from 19–20% to ~2%.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Chrome renders the page in a renderer process and composites layers in a separate GPU process. In Firefox the page (content) process is roughly the renderer. Every percentage here is CPU time as a share of one core, not GPU load.&lt;/p&gt;

&lt;p&gt;The default cat is 60×48 CSS pixels. A rectangular hit box would also catch clicks in the empty space around its ears and tail, so I clipped the clickable area to the cat's outline with &lt;code&gt;clip-path&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I put that clip on the canvas that was already moving.&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%2Fhpt6mjlx1610da6qytyz.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%2Fhpt6mjlx1610da6qytyz.gif" alt="Tabloaf walking along the bottom of Wikipedia's Cat article in Chrome" width="760" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Moving the walk off the frame loop
&lt;/h2&gt;

&lt;p&gt;An earlier version saved CPU by stepping the walk one art pixel at a time, but it looked jerky. I went back to moving it on every display frame with &lt;code&gt;requestAnimationFrame&lt;/code&gt; (rAF).&lt;/p&gt;

&lt;p&gt;Then I moved straight walks and runs to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/animate" rel="noopener noreferrer"&gt;&lt;code&gt;Element.animate()&lt;/code&gt;&lt;/a&gt;. JavaScript wakes only to redraw the legs (the next sprite frame) and to decide what the cat does next. Everything else (the yarn game, dragging, jumps) still runs on rAF.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;Element.animate()&lt;/code&gt; the browser moves the cat, so my code computes its x from the animation's start time and speed. If you grab the cat halfway across the screen, I cancel the animation and pin the cat where it was drawn.&lt;/p&gt;

&lt;p&gt;In Chrome the renderer dropped. The GPU process barely moved.&lt;/p&gt;

&lt;h2&gt;
  
  
  The clip on the moving canvas
&lt;/h2&gt;

&lt;p&gt;I thought &lt;code&gt;image-rendering: pixelated&lt;/code&gt; was the expensive part. Turning it off did almost nothing. Taking the clip off the moving canvas cut the GPU process by more than half. I didn't dig into why.&lt;/p&gt;

&lt;p&gt;So I split the cat into two elements: the canvas with &lt;code&gt;pointer-events: none&lt;/code&gt;, and an empty hit element that carries the outline and gets the clicks. Both move on the same animation clock:&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="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pointerEvents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"none"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// the picture ignores the pointer&lt;/span&gt;
&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clipPath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;outlinePath&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// an empty div takes the clicks&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;animate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frames&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;startTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// same clock for both&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Chrome, one walking sample per stage (a separate session):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stage&lt;/th&gt;
&lt;th&gt;Renderer&lt;/th&gt;
&lt;th&gt;GPU process&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;rAF, clip on the canvas&lt;/td&gt;
&lt;td&gt;~12%&lt;/td&gt;
&lt;td&gt;~14%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Web Animations, clip on the canvas&lt;/td&gt;
&lt;td&gt;~8%&lt;/td&gt;
&lt;td&gt;~13%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Web Animations, separate hit element&lt;/td&gt;
&lt;td&gt;~8%&lt;/td&gt;
&lt;td&gt;~6%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In Firefox, the big win came from the earlier step: the move to Web Animations alone cut its page process by more than two-thirds.&lt;/p&gt;

&lt;h2&gt;
  
  
  The legs were still changing the hit outline
&lt;/h2&gt;

&lt;p&gt;The hit outline still changed with every leg position, and a walk cost ~4–5% in Firefox's page process. With the hit element hidden it was ~2%: useless, since you can't grab the cat, but it showed the floor.&lt;/p&gt;

&lt;p&gt;I kept the outline but stopped changing it with the legs: during an animated walk, the hit outline is one shape that covers every leg position. That leaves about a quarter of the empty space in the cat's box clickable while it walks. Other states keep their exact outlines.&lt;/p&gt;

&lt;p&gt;Firefox's page process came down to the same ~2% as with the hit element hidden. In Chrome the single outline made no measurable difference.&lt;/p&gt;

&lt;p&gt;Why not test the pixel mask in JavaScript and skip &lt;code&gt;clip-path&lt;/code&gt;? The browser decides whether a touch scrolls the page by looking at the element under the finger, before any of my handlers run. Without a real element shaped like the cat, a touch on the cat would scroll the page. The grab cursor also has to change when the cat walks under a still mouse. I haven't benchmarked that approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before and after
&lt;/h2&gt;

&lt;p&gt;The older build used rAF with the clip on the canvas. The optimized one has all three changes: Web Animations, the separate hit element, and one outline for the walk. I alternated them twice in each browser; one optimized Firefox run didn't complete.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Walk&lt;/th&gt;
&lt;th&gt;Older&lt;/th&gt;
&lt;th&gt;Optimized&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Chrome renderer&lt;/td&gt;
&lt;td&gt;12–13%&lt;/td&gt;
&lt;td&gt;~8%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome GPU process&lt;/td&gt;
&lt;td&gt;15–17%&lt;/td&gt;
&lt;td&gt;~7%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox page process&lt;/td&gt;
&lt;td&gt;19–20%&lt;/td&gt;
&lt;td&gt;~2%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;It didn't get any less smooth. In a Chrome trace, the 95th-percentile frame time on walks stayed at ~17.5 ms before and after, with no frame over 20 ms.&lt;/p&gt;

&lt;p&gt;The yarn game is still the expensive part: its thread is redrawn on every frame.&lt;/p&gt;

&lt;h2&gt;
  
  
  About the measurements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;October 20, 2026, a MacBook Air M4, 60 Hz display at DPR 2, real browser windows.&lt;/li&gt;
&lt;li&gt;Playwright's Chromium build and Firefox 157.&lt;/li&gt;
&lt;li&gt;en.wikipedia.org/wiki/Cat, the cat at its default size, 10–12 seconds per sample.&lt;/li&gt;
&lt;li&gt;Chrome numbers come from &lt;a href="https://chromedevtools.github.io/devtools-protocol/tot/SystemInfo/" rel="noopener noreferrer"&gt;CDP process info&lt;/a&gt;, Firefox numbers from &lt;code&gt;ChromeUtils.requestProcInfo()&lt;/code&gt; over the debugging connection.&lt;/li&gt;
&lt;li&gt;As a control, I moved a plain 60×48 canvas with rAF in every session. It read about the same each time, so the sessions are comparable.&lt;/li&gt;
&lt;li&gt;The numbers include the live page. I measured dev builds, not what's in the stores now.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI agents helped me implement the alternatives and write the benchmark harnesses. They also helped with the sprites and with looking up which coat patterns are common in different parts of the world, so there's a good chance one looks like your cat.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tabloaf.dmitryq.com/" rel="noopener noreferrer"&gt;Try the browser demo without installing anything&lt;/a&gt;&lt;/p&gt;

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