is-plain-object
is-plain-object copied to clipboard
imp: Security and performance improvements
- 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();
cc @jonschlinkert