fast-prop-del
Fast property delete.
With this library you can delete object properties and then turn the object to fast property mode. Aditionally, you can turn common objects to fast property mode or add new properties to an object forcing the object to be fast property mode.
In v8 engine an object has two ways of representation:
- Dictionary mode (also known as normalized objects)
- Fast property mode
How do I know if an object is Dictionary or Fast property mode?
When you use your object as if it was a hash table your object may turn to dictionary mode. For example, when you add several properties dinamically or when you delete a property.
This makes the object have worse performance when you access an object property.
You can learn more:
You can try the performance using as example performance.js
- Iterate dictionary: 57ms
- Iterate fastProp: 9ms
6 times faster!
Install
$ npm install fast-prop-del
Test
$ npm install$ npm test
Check performance
$ npm install$ node --allow-natives-syntax test/performance.js
Usage
Remove property
var propDel = propDel; var obj = 'bar': 'foo';;console;// obj => {} var obj = 'bar': 'foo': 'bar' ;;console;// obj => {'bar': null} ;// Error => Invalid object
Remove several properties
var propDel = propDel; var obj = 'a': 'a' 'b': 'b' 'c': 'c' 'd': 'd';;console;// obj => {'d': 'd'} var obj = 'a': 'a' 'b': 'b' 'c': 'c' 'd': 'd';;console;// obj => {}
Turn object into fast properties mode
var turnToFastProp = turnToFastProp; var obj = 'bar': 'foo';delete objbar;;
Adding one property to an object turning the object into fast properties mode
var propAdd = propAdd; var obj = 'bar': 'foo';;console;// obj => {'bar': 'foo', 'bar2': 'foo2'}
Adding several properties to an object turning the object into fast properties mode
var propAdd = propAdd; var obj = 'bar': 'foo';var objToMix = 'a': 'a' 'b': 'b';;console;// obj => {'bar': 'foo', 'a': 'a', 'b': 'b'}