<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dan Ristic on Medium]]></title>
        <description><![CDATA[Stories by Dan Ristic on Medium]]></description>
        <link>https://medium.com/@sharpper?source=rss-322ed4207783------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nmAxog6NSsESZux2.jpeg</url>
            <title>Stories by Dan Ristic on Medium</title>
            <link>https://medium.com/@sharpper?source=rss-322ed4207783------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:59:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sharpper/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hardware Acceleration for Browsers]]></title>
            <link>https://medium.com/@sharpper/hardware-acceleration-for-browsers-a3841d8b2d74?source=rss-322ed4207783------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3841d8b2d74</guid>
            <category><![CDATA[graphics]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Dan Ristic]]></dc:creator>
            <pubDate>Fri, 10 Jun 2016 05:07:35 GMT</pubDate>
            <atom:updated>2016-06-10T05:07:35.645Z</atom:updated>
            <content:encoded><![CDATA[<p>I talk to many fledgling web developer candidates about hardware acceleration. One of my favorite open-ended questions I ask is, “How do you get CSS animations to play smoothly?”. The typical answer tends to be short talking about slapping some transform properties on an element and watching it go. When I dig deeper and ask <em>why</em> does it do that I hit a brick wall. Many web developers seem to know exactly what properties to use without knowing what any of them actually do behind the scenes. These are the same developers who may end up lost or confused when their application seems slow!</p><p>What I want to provide in this article is the <em>why</em> part of hardware acceleration in the browser. I feel that it is important to know what is happening under the hood to develop a truly well built user experience. Compare this with driving a race car: many people can press the gas pedal to “go fast” but the person who knows the finer points of shifting a transmission will come out on top.</p><h4>Hardware in your Software</h4><p>The key part of understanding hardware acceleration is the term <em>hardware</em>. It turns out the concept of hardware acceleration is fairly old. In the early days of programming games, the way to push more pixels was to create something called a graphical processing units. They had limited resources (and still do) and needed to create a specialized chip that was designed specifically for pushing pixels. The concept of the GPU was a chip dedicated to drawing sprites and other figures on the screen to make the games have better graphics which sold more units.</p><p>Fast forward almost 40 years and this concept still remains today. Many computers have a CPU which is dedicated to general processing and a GPU which is dedicated to <em>graphics</em> processing. This is also why a simple text editor can take five minutes to open up while your typical video game can push one-million triangles sixty times per second.</p><h4>Enter the Browser</h4><p>So this history lesson is great but what about browsers? Well along the way someone figured out that <em>graphics</em> can mean anything, including the pixels on your browser screen! During the rise of the iPhone engineers started to learn that good user experience can sell more units. They needed to push the web just as fast as applications built natively for the operating system. By diverting some of the rendering to the GPU, which is already specialized to put pixels on the screen quickly, they found they could speed up the rendering of web pages.</p><p>This step is actually called <em>accelerated compositing, or </em>AC, for short. The reasoning behind it is that you draw some stuff on your CPU and some stuff on your GPU, and then you <em>composite</em> them together to create a single image. If you have used a graphics program such as Sketch or Photoshop, you can think of AC as using different layers and putting those layers on top of each other. Each layer is represented in memory and can be drawn at rates over 60 times per second.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*VFgWqczYnhXtIDV3iH5m3A.png" /><figcaption>Example of multiple layers in memory</figcaption></figure><p>There are big trade offs for offloading rendering to the GPU however. Think about running a video game on your laptop: it runs out of battery fast. This is avoided by drawing only <em>some</em> things on the GPU and the rest on the CPU. This way it gets the best of both worlds: fast rendering where it is needed with lower power consumption than a video game. This is also leading the way for specific CSS properties like <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/will-change">https://developer.mozilla.org/en-US/docs/Web/CSS/will-change</a>. This means that the CPU and GPU have to work in harmony to create the optimal solution.</p><p>A CPU is specifically designed to handle nearly any task your computer wants to do. Take, for example, drawing text on the screen. To draw a single character you have to know a lot about how the character is shaped as well as what size to draw it at. It is extremely difficult to take one letter at a single size and simple enlarge or shrink it to the font size you want to draw it at. This is where the CPU can come in with pixel perfect techniques for rendering characters.</p><p>Now take, on the other hand, animating an image across the screen. This is a relatively simple task: draw a N x N box of pixels at a single 2D location. You can even break this down further and say I want to draw a single pixel N x N times. This is the power of the GPU. It is an expert at doing a single task millions or even billions of times per second.</p><h4>Putting them Together</h4><p>Let’s say you draw a word at a given size. Now let’s say we want to move that word around the screen really quickly in an animation. The best way to do this is to combine the best of both using a series of steps:</p><ol><li>Draw the word at the given font size with the given font on the CPU</li><li>Save this image, or <em>texture</em>, and give that to the GPU as a N x N box of pixels</li><li>Every frame the word moves, redraw our box of pixels using the GPU</li><li>If the word changes, redraw the box using the CPU and update the image our GPU has</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*U-RlH6lizIEKV6fRQB64Hw.png" /><figcaption>How the CPU and GPU work together</figcaption></figure><p>This is nowhere near the magical process that web developers might think it is. This is why changing text rapidly at the same time as animating it can be slow, where as just animating an image can be fast. Rendering text is also just one use case of hundreds that can make or break the performance of a page.</p><p>To get the optimal experience it is best to start putting your application into CPU and GPU buckets. If you want to animate a DIV element smoothly it should get a transform property and stay that way until it gets removed from the screen. If something is not animating or moving over time it should not get a transform property. This informs the browser about which pipeline to use and allows the browser to optimize rendering as much as possible.</p><h4>Scratching the Surface</h4><p>Although this is just a brief overview, having a foundation of knowledge in the functions of the GPU and CPU can go a long way. Even though the browser is always finding new techniques to render things faster they are still built on the same foundations. You will start to find your web applications performing better and consuming less memory which should result in a better user experience.</p><p>It is my personal belief that UI engineers should have a firm understanding of what is happening beneath the surface. If you enjoyed this article, leave a comment! It will encourage me to write more behind the scenes articles in the future.</p><p>I recommend <a href="http://www.html5rocks.com/en/tutorials/speed/layers/">http://www.html5rocks.com/en/tutorials/speed/layers/</a> next to learn more!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3841d8b2d74" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>