vorg / geom-builder

Simplicial-complex-like geometry builder backed by typed arrays
MIT License
14 stars 2 forks source link

Abysmal performance due to using arguments in each add* function call #2

Closed vorg closed 6 years ago

vorg commented 6 years ago

Geom builder allows to do addPosition([x, y, z]) and addPosition(x, y, z) to avoid vector allocation. To enable this I use arguments parameter. Turns out it allocates a lot of junk in Firefox causing GC hiccups and has impact on CPU in Safari and Chrome as well.

//1 old
GeomBuilder.prototype.addPosition = function (pos) {
  var values = arguments[0].length ? pos : arguments

//2 new, best
GeomBuilder.prototype.addPosition = function (pos) {
  var values = pos

// 3 better than 1, but still slower than 2
GeomBuilder.prototype.addPosition = function (...pos) {
  var values = pos[0].length ? pos[0] : pos