Comment #10 on issue 505 by [email protected]: Implement function denesting optimization
http://code.google.com/p/v8/issues/detail?id=505

This blog post http://blog.trevnorris.com/2013/08/long-live-callbacks.html has an example that I think *may* be what is being referenced here. The last time this bug was touched was in 2009. Since the release of ES5, strictness should make such a non-closure first-class function much more viable. The example used in the blog, is:

var SB = require('buffer').SlowBuffer;

function runner(cb, arg) {
  process.nextTick(function() {
    cb(arg);
  });
}


var iter = 2e4;

for (var i = 0; i < iter; i++) {
  runner(function genPrimes(max) {
    var primes = [];
    var len = ((max / 8) >>> 0) + 1;
    var sieve = new SB(len);
    sieve.fill(0xff, 0, len);
    var cntr, x, j;
    for (cntr = 0, x = 2; x <= max; x++) {
      if (sieve[(x / 8) >>> 0] & (1 << (x % 8))) {
        primes[cntr++] = x;
        for (j = 2 * x; j <= max; j += x) {
          sieve[(j / 8) >>> 0] &= ~(1 << (j % 8));
        }
      }
    }
    return primes;
  }, i);
}

The blog author concludes that moving the definition of `genPrimes(max)` outside of the scope results in a 9x runtime improvement. This seems to me to be a "gotcha". If strict-mode requests all variables to be predeclaired then this would be an easy optimization that I imagine would be beneficial in a lot of use cases.

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to