@optimal/object
v0.1.0
Published
Force V8 to optimize an object's properties or check its status
Downloads
1
Maintainers
Readme
@optimal/object
Force V8 to optimize an object's properties or check its status.
Use this when:
- the object ends up in slow mode
- it's not possible to refactor code to avoid slow mode (such as defining all the properties on it ahead of time and only altering their values, not adding properties, and not deleting them)
- an object's properties are accessed often enough to affect performance
The optimization doesn't require '--allow_natives_syntax'
; only the check does.
Check if an object's property access is in optimized mode with optimize.check()
. This tries to enable the flag '--allow_natives_syntax'
, so, use in testing and performance benchmarking. (The flag is required in order to check the optimization status.)
See V8 test
Install
npm install @optimal/object --save
Usage
// 1. optimize a an object
var optimize = require('@optimal/object')
var object = {
key :'value',
some:'thing',
and :'more',
}
// trigger slow mode
delete object.and
// back to fast access
optimize(object)
// 2. test an object to know if it's optimized:
var someOtherObject = getSomeOtherObject()
result = optimize.check(someOtherObject) // returns true or false