title: How to constantly move SVG paths without losing performance
body: <p>I am trying to do a mobile game where I draw 6 SVG paths and I move then through the screen (from top to bottom) constantly. I am manipulating the paths with a simple javascript that  updates some variables value and use them to set the attribute "d" of the paths. Like the example below:</p>
  
  <pre><code>setInterval(scrollPaths, 17); // ~ 60 fps
  
  function scrollPaths() {
  
    // leftYPoints is an array of points defined earlier and scrollSpeed is an integer value (e.g. 2)
    for (var i = 0; i &lt; leftYPoints.length; i++) leftYPoints[i] += scrollSpeed;
  
    // then I change the paths attribute
    var pathAttribute = "M"+ leftXPoints[0] + leftYPoints[0]
        + " L" + leftXPoints[1] + leftYPoints[1];
  
    document.getElementById("leftpath").setAttribute("d", pathAttribute);
    document.getElementById("righpath").setAttribute("d", pathAttribute);
    ... // continue to do that with the other paths, changing some variables only
  
  }
  </code></pre>
  
  <p>The javascript itself runs very fast (scrollPaths takes about 5ms every time) and runs perfectly on the browser. But when I test the script in the mobile browser it seems that theres is a lot of lag on the paths. You can see that the paths are not scrolling smoothly. So I tried to decrease the value of <code>scrollSpeed</code> to a very small value but that did not solve it. So I thought the problem was related to the rendering method of the mobile browser or something like that. I tried to find some answers but nothing solved my problem. Then I found AmeliaBR`s answer here <a href="https://stackoverflow.com/questions/21629134/how-do-you-move-an-svg-around-a-webpage-without-triggering-slow-redraws">How do you move an SVG around a webpage without triggering slow redraws?</a> where she says that it is better to use the transform attribute because the browser will understand it as it should just move some content that was already rendered instead of re-calculating the whole layout. So I tried to do that like this:</p>
  
  <pre><code>var newYPos = 1;
  
  setInterval(scrollPaths, 17); // ~ 60 fps
  
  function scrollPaths() {
  
    // increased the position of the paths
    newYPos += 1;
  
    // then I did the transform of the paths with a group &lt;g&gt;
    document.getElementById("pathsgroup").setAttribute("transform", "translate(0," + value + ")");
  
  }
  </code></pre>
  
  <p>But unfortunately the result was not very effective. The javascript ran a little faster but the lag effect of the paths is still happening. So I am here, asking:</p>
  
  <ol>
  <li>Does anyone knows what is happening?</li>
  <li>Is there a better way to do that?</li>
  <li>Or the problem is that mobile browsers are not ready for that yet (they still lack performance)?</li>
  </ol>
  
  <p>Not sure if it helps but I tested it on a Nexus 5 with Chrome (supposed to have a very good performance).</p>
  
  <p>Thanks.</p>