What does compound let/const assignment mean?

前端 未结 1 1648
野性不改
野性不改 2021-01-03 19:54

There is an article Optimization killers in wiki of Bluebird library. In this article there is a phrase:

Currently not optimizable:
...
F

相关标签:
1条回答
  • 2021-01-03 20:47

    Yes, that seems to be exactly what it means. I had the following code (irrelevant additional lines removed):

    function updatePlayer(player) {
        let direction = player.getDirection();
        if (player.isPressingLeft()) {
            direction += angleChange;
        }
        if (player.isPressingRight()) {
            direction -= angleChange;
        }
        player.setDirection(direction);
    }
    

    updatePlayer generated a warning, Not optimized: Unsupported let compound assignment, in Chrome's Profiles tab, so instead of l += r I tried l = l + r and got a significant, consistent performance improvement.

    jsPerf shows that let compound assignments are indeed extremely slow in Chrome 49.0.2623, compared to l = l + r or var! I guess this will be fixed in a future version, since neither Firefox nor IE11 nor Edge is affected, and since Google apparently know about the issue.

    0 讨论(0)
提交回复
热议问题