P5.js: avoid use of arguments in square()

Created on 24 Feb 2019  路  2Comments  路  Source: processing/p5.js

brought up in #3525 and https://github.com/processing/p5.js/pull/3531#issuecomment-466808663

such use of the arguments array causes deoptimization in many js jits

alternate implementation proposed by @Spongman :

p5.prototype.square = function(x, y, s, tl, tr, br, bl) {
  this.rect(x, y, s, s, tl, tr, br, bl);
};

this should be more performant than the current implementation (which uses arguments).

https://github.com/processing/p5.js/blob/571bd7a52ae7afdb056cfc0b9ea53927514f507c/src/core/shape/2d_primitives.js#L517-L522

core

Most helpful comment

just to expand on this: in general whenever the arguments object is mutated, or passed to a method (except as the 2nd argument of function.apply) the runtime has to copy the stack-allocated arguments object to a heap-allocated, garbage collected temporary proxy object. additionally, the added complexity of this often can result in the method no longer being eligible for native code generation.

All 2 comments

just to expand on this: in general whenever the arguments object is mutated, or passed to a method (except as the 2nd argument of function.apply) the runtime has to copy the stack-allocated arguments object to a heap-allocated, garbage collected temporary proxy object. additionally, the added complexity of this often can result in the method no longer being eligible for native code generation.

I'd like to work on this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stalgiag picture stalgiag  路  3Comments

ogoossens picture ogoossens  路  3Comments

sps014 picture sps014  路  3Comments

bassamanator picture bassamanator  路  3Comments

Vbbab picture Vbbab  路  3Comments