npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bnaya/objectbuffer

v0.32.1

Published

Object-like api, backed by an array buffer

Downloads

277

Readme

ObjectBuffer: object-like API, backed by a [shared]arraybuffer

npm version Coverage Status Gitpod Ready-to-Code

For Modern browsers and node.

Save, read and update plain javascript objects into ArrayBuffer, using regular javascript object api, without intermediate serialization/deserialization.

No pre-defined schema is required. In other words, It's a user-land implementation of javascript objects, using a single ArrayBuffer as the heap.

That's enables us to transfer or share objects with a WebWorker or other, same-origin, browsing contexts without data duplication or full serialization.

🐉🐉🐉 Adventurers Beware 🐉🐉🐉

Using this library, and workers in general, will not necessarily make you code runs faster.
First be sure where your bottlenecks are, and if you don't have a better and more simple workaround.
I personally also really like what's going on around the main thread scheduling proposal and react userland scheduler that powers concurrent react

Quick example

import { createObjectBuffer, getUnderlyingArrayBuffer } from "@bnaya/objectbuffer";

const initialValue = {
  foo: { bar: new Date(), arr: [1], nesting:{ WorksTM: true } }
};
// ArrayBuffer is created under the hood
const myObject = createObjectBuffer(
  // size in bytes
  1024,
  initialValue
);

myObject.additionalProp = "new Value";
myObject.arr.push(2);

const arrayBuffer = getUnderlyingArrayBuffer(myObject);

Play with it (codesandbox)

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

Getting involved

Participants is Adhere to the Code of Conduct.
The quickest way to get up and running is via Gitpod Ready-to-Code and to run the tests.

Go over the contributing document.
Pick an issue with "good first" or "help wanted", or do some cool by your own!

Feel free to open an issue, or contact me directly at [email protected]

API reference

link

Why

Exchanging plain objects with WebWorkers 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 a copy, and SharedArrayBuffer can be directly shared, but out of the box, it's hard to use ArrayBuffer as more than a TypedArray.

Disclaimer / Motivation

I'm working on it mostly from personal interest, It's not in use in any production use-case.
Before putting any eggs in the basket, please go over the implementation details document

What's working

  • strings
  • number
  • objects (with nesting and all)
  • arrays
  • Date
  • BigInt
  • Internal references (foo.bar2 = foo.bar will not create a copy, but a reference)
  • Automatic reference counting, to dispose a value you need to use the disposeWrapperObject or to have WeakRef support
  • Internal equality between objects (foo.bar === foo.bar will be true)
  • global lock for shared memory using Atomics (I hope its really working)

Caveats & Limitations

  • Need to specify size for the ArrayBuffer. When exceed that size, exception will be thrown. (Can be extended later with a utility function, but not automatically)
  • Size must be multiplication of 8
  • Set, Map, Object keys can be only string or numbers. no symbols or other things
  • No prototype chain. no methods on the objects
  • Adding getters, setters, will not work/break the library
  • deleting/removing the current key of Map/Set while iteration will make you skip the next key #60

What's not working yet, but can be

  • bigint bigger than 64 bit

What's probably never going to work

  • Anything that cannot go into JSON.stringify
  • Symbol

If you came this far, you better also look at: