Is strict mode more performant?

前端 未结 4 486
你的背包
你的背包 2020-11-30 02:50

Does executing javascript within a browser in \'strict mode\' make it more performant, in general? Do any of the major browsers do additional optimisation or use any other t

4条回答
  •  失恋的感觉
    2020-11-30 03:16

    For the most part, no. If you closely examine the ECMAScript 5 standards document, you'll notice that pretty much all occurrences of Strict Mode in the pseudo-code algorithms amount to:

      if (isStrictMode) {
          //throw an (early) SyntaxError or TypeError
      }
      else {
          //return
      }
    

    There's two things to note about this:

    1. The checks on Strict Mode didn't exist in ECMAScript 3. While it's relatively lightweight, conforming implementations of JavaScript are now running at least one extra conditional check compared to their ECMAScript 3 counterparts. Yeah...I know a single check like this burns very few clock cycles, but little things add up
    2. Because Strict Mode is primarily a parse time feature of JavaScript, your favorite browser isn't going to show much of a performance decrease when Strict Mode is enabled for some website (e.g., SunSpider). That is, the performance degrade occurs before code is executed meaning it could be perceptible to end-users but is largely immeasurable using the Date object to measure block execution time

提交回复
热议问题