@optimal/object

0.1.0 • Public • Published

@optimal/object

Build Status Dependency Status npm version Coverage Status

Force V8 to optimize an object's properties or check its status.

Use this when:

  1. the object ends up in slow mode
  2. 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)
  3. 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

Others

  1. @optimal/fn

MIT License

Package Sidebar

Install

npm i @optimal/object

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • elidoran