{"id":19180192,"url":"https://github.com/bnaya/objectbuffer","last_synced_at":"2025-04-07T13:04:20.555Z","repository":{"id":46780439,"uuid":"204289521","full_name":"Bnaya/objectbuffer","owner":"Bnaya","description":"JavaScript Object like api, backed by an arraybuffer","archived":false,"fork":false,"pushed_at":"2024-05-14T07:48:38.000Z","size":7159,"stargazers_count":176,"open_issues_count":31,"forks_count":5,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-03-31T12:06:57.075Z","etag":null,"topics":["arraybuffer","javascript","sharedarraybuffer","sharedmemory"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bnaya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-25T12:13:03.000Z","updated_at":"2025-03-11T06:28:30.000Z","dependencies_parsed_at":"2024-05-14T05:27:52.860Z","dependency_job_id":"fe7410af-b639-4297-92b5-db8400fb8235","html_url":"https://github.com/Bnaya/objectbuffer","commit_stats":{"total_commits":208,"total_committers":3,"mean_commits":69.33333333333333,"dds":"0.019230769230769273","last_synced_commit":"eab6073fdd2911dfc71606049921f347e5b49e25"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bnaya%2Fobjectbuffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bnaya%2Fobjectbuffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bnaya%2Fobjectbuffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bnaya%2Fobjectbuffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bnaya","download_url":"https://codeload.github.com/Bnaya/objectbuffer/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657275,"owners_count":20974344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arraybuffer","javascript","sharedarraybuffer","sharedmemory"],"created_at":"2024-11-09T10:48:23.727Z","updated_at":"2025-04-07T13:04:20.531Z","avatar_url":"https://github.com/Bnaya.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ObjectBuffer: object-like API, backed by a [shared]arraybuffer\n\n[![npm version](https://badge.fury.io/js/%40bnaya%2Fobjectbuffer.svg)](https://badge.fury.io/js/%40bnaya%2Fobjectbuffer)\n[![Coverage Status](https://coveralls.io/repos/github/Bnaya/objectbuffer/badge.svg)](https://coveralls.io/github/Bnaya/objectbuffer) [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/Bnaya/objectbuffer)   \n\n\nFor Modern browsers and node.\n\nSave, read and update plain javascript objects into `ArrayBuffer`, using regular javascript object api,\nwithout intermediate serialization/deserialization.  \n\nNo pre-defined schema is required.\nIn other words, It's a user-land implementation of javascript objects, using a single ArrayBuffer as the heap.\n\nThat's enables us to `transfer` or share objects  with a `WebWorker` or other, same-origin, browsing contexts without data duplication or  full serialization.\n\n## 🐉🐉🐉 Adventurers Beware 🐉🐉🐉\nUsing this library, and workers in general, will not necessarily make you code runs faster.  \nFirst be sure where your bottlenecks are, and if you don't have a better and more simple workaround.  \nI personally also really like what's going on around the [main thread scheduling proposal](https://github.com/WICG/main-thread-scheduling) and [react userland scheduler](https://www.npmjs.com/package/scheduler) that powers concurrent react\n\n## Quick example\n\n```js\nimport { createObjectBuffer, getUnderlyingArrayBuffer } from \"@bnaya/objectbuffer\";\n\nconst initialValue = {\n  foo: { bar: new Date(), arr: [1], nesting:{ WorksTM: true } }\n};\n// ArrayBuffer is created under the hood\nconst myObject = createObjectBuffer(\n  // size in bytes\n  1024,\n  initialValue\n);\n\nmyObject.additionalProp = \"new Value\";\nmyObject.arr.push(2);\n\nconst arrayBuffer = getUnderlyingArrayBuffer(myObject);\n\n```\n\n## Play with it (codesandbox)\n\n* [Sort Array on worker (comlink)](https://codesandbox.io/s/objectbuffer-comlink-demo-sort-array-on-webworker-no-data-copy-je3ni)\n* [Sort Array on worker (no comlink)](https://codesandbox.io/s/objectbuffer-demo-sort-array-on-webworker-no-data-copy-xmpl5)\n\nSee also [main.js](playground/main.js) for shared memory example.\nto run it: clone the repo, `yarn install` and `yarn browser-playground`\n\n## Getting involved\n\nParticipants is Adhere to the [Code of Conduct](./CODE_OF_CONDUCT.md).  \nThe quickest way to get up and running is via [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/Bnaya/objectbuffer) and to run the tests.\n\nGo over the [contributing document](CONTRIBUTING.md).  \nPick an issue with [\"good first\" or \"help wanted\"](https://github.com/Bnaya/objectbuffer/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22), or do some cool by your own!\n\nFeel free to open an issue, or contact me directly at [me@bnaya.net](mailto:me@bnaya.net)\n\n## API reference\n\n[link](docs/generated/README.md)\n\n## Why\n\nExchanging plain objects with `WebWorkers` is done by serializing and copying the data to the other side.  \nfor some use-cases, it's slow and memory expensive.  \n`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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays).  \n## Disclaimer / Motivation\n\nI'm working on it mostly from personal interest, It's not in use in any production use-case.  \nBefore putting any eggs in the basket, please go over the [implementation details document](docs/implementationDetails.md)\n\n## What's working\n\n* strings\n* number\n* objects (with nesting and all)\n* arrays\n* Date\n* BigInt\n* Internal references (`foo.bar2 = foo.bar` will not create a copy, but a reference)\n* Automatic reference counting, to dispose a value you need to use the `disposeWrapperObject` or to have WeakRef support\n* Internal equality between objects (`foo.bar === foo.bar` will be true)\n* global lock for shared memory using [Atomics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) (I hope its really working)\n\n## Caveats \u0026 Limitations\n\n* 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)\n* Size must be multiplication of 8\n* Set, Map, Object keys can be only string or numbers. no symbols or other things\n* No prototype chain. no methods on the objects\n* Adding getters, setters, will not work/break the library\n* deleting/removing the current key of Map/Set while iteration will make you skip the next key [#60](https://github.com/Bnaya/objectbuffer/issues/60)\n\n### What's not working yet, but can be\n\n* `bigint` bigger than 64 bit\n\n### What's probably never going to work\n\n* Anything that cannot go into `JSON.stringify`\n* `Symbol`\n\n## If you came this far, you better also look at:\n* [GoogleChromeLabs/buffer-backed-object](https://github.com/GoogleChromeLabs/buffer-backed-object#readme) \n* [FlatBuffers](https://google.github.io/flatbuffers/flatbuffers_guide_use_javascript.html)\n* And there must be more of these, look them up\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnaya%2Fobjectbuffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnaya%2Fobjectbuffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnaya%2Fobjectbuffer/lists"}