Proposal: Abstract References

Andreas Rossberg rossberg at google.com
Wed Oct 22 06:46:04 PDT 2014


On 22 October 2014 14:18, Andrea Giammarchi <andrea.giammarchi at gmail.com> wrote:
> FWIW the Multiple WeakMaps approach seems to be 2X ( Chrome ) up to 3X ( FF
> Nightly ) faster than single WeakMap approach but I don't know how much
> WeakMap instances cost in terms of GC operations so this bench might be very
> pointless ( and surely it's premature )
>
> Weirdly enough, Chrome Canary seems to be able to optimize the single
> WeakMap approach pretty well, with a gap of 1.25X faster perfs on multiple
> WMs.

If you really want to micro-benchmark, then perhaps at least use more
reasonable code that avoids unnecessary indirections distorting the
results. That is:

```js
var PrivateCoordinatesMWM = (function () {
  var x_ = new WeakMap
  var y_ = new WeakMap

  function PrivateCoordinatesMWM(x, y) {
    x_.set(this, x)
    y_.set(this, y)
  }

  PrivateCoordinatesMWM.prototype.toString = function toString() {
    return ''.concat('[', x_.get(this), y_.get(this), ']')
  };

  return PrivateCoordinatesMWM
}())
```

This also happens to be more readable. ;)

/Andreas


More information about the es-discuss mailing list