Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bnaya/objectbuffer

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bnaya/objectbuffer

Object like api, backed by an array buffer

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
decreased by-81.76%
Maintainers
1
Weekly downloads
 
Created
Source

WIP: object-like api, backed by a [shared]arraybuffer.

For Modern browsers and node. Zero direct dependencies.

The library offers you an api that have the look & feel of a regular javascript object, but the data is saved to an ArrayBuffer that can be shared or transferred to a WebWorker.
The library is still not complete, and will never offer full compatibility with plain js objects due, to the nature of the language and the problems space.

Play with it:

Edit objectbuffer demo

See main.js for shared memory example. to run it: clone the repo, yarn install and yarn browser-playground

Why?

Exchanging data with WebWorkers (other than ArrayBuffer) is done by serializing and copying the data to the other side.
for some use-cases, it's slow and memory expensive. ArrayBuffer can be transferred without copy, and SharedArrayBuffer can be directly shared, but out of the box, it's hard to use ArrayBuffer as more than a TypedArray.

SharedArrayBuffer and ArrayBuffer

Motivation

Personal interest, Maybe will be useful as shared memory primitive, and communicating with WASM. Maybe state management with shared memory across workers?

What do we have in hand?

It's working! but very unoptimized (eg objects are simple linked lists), only append data (no logic to reuse unreachable memory) and its not extending the backing arraybuffer size by itself. if you exceed the sb size, an exception will be thrown.
ArrayBuffer.prototype.transfer is still not supported anywhere, so we can't do that efficiently anyhow

What's working:

  • Kinda what ever that can go into JSON.stringify
  • objects
  • arrays (without methods yet)
  • global lock using Atomics (i hope its really working)

Missing parts

  • array methods
  • Date
  • Map On primitive key/value
  • Set On primitive values

What's not working yet, but can be:

  • bigint bigger than 64 bit

What's probably never going to work (convince me otherwise in an issue):

  • Anything that cannot go into JSON.stringify
  • Symbol
  • Circularities

"design" doc:

https://docs.google.com/document/d/1-UlUyH3HgOrN58avyScZlfjQtfJxgVwK_yE35mQHpYw/edit?usp=sharing

Contribution / Collaboration

There's a huge place for optimizations, code hygiene, and features!
Feel free to open issues and maybe implementing missing parts

FAQs

Package last updated on 30 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc