is-plain-object icon indicating copy to clipboard operation
is-plain-object copied to clipboard

imp: Security and performance improvements

Open xobotyi opened this issue 4 years ago • 1 comments

  • performance improve: better to store prototype functions to variable to avoid lookup on each call;
  • reliability improve: prot.hasOwnProperty is not secure due it can be missing or redefined - better to use Object.prototype.hasOwnProperty;
  • performance improve: better to create variables on demand;

All given changes slightly improved overall performance (local is this PR):

array
  npm x 903,517,271 ops/sec ±0.06% (98 runs sampled)
  local x 905,053,882 ops/sec ±0.09% (98 runs sampled)
Fastest is local

object
  npm x 24,252,725 ops/sec ±1.83% (90 runs sampled)
  local x 25,275,804 ops/sec ±1.33% (94 runs sampled)
Fastest is local

benches are simple:


const arr = [1, 2, 3];
const obj = { a: 123, b: true };

suite.clone({ name: 'array' })
     .add('npm', () => {npm(arr)})
     .add('local', () => {local(arr)})
     .run();

suite.clone({ name: 'object' })
     .add('npm', () => {npm(obj)})
     .add('local', () => {local(obj)})
     .run();

xobotyi avatar Oct 22 '19 09:10 xobotyi

cc @jonschlinkert

TrySound avatar Oct 22 '19 09:10 TrySound