Comments (6)
Hi! Have you done some profiling/benchmarking? If yes, what are the results you've got?
I've just published a library similar to this one (@3m1/binary-object
), but with fixed schema defined using in-class @decorators
. I archived a 2-3 times slower instantiation/read/write operations compared to normal JS objects, with an extra 2-3 times heap memory usage on instantiation. If this is good for you, I can take a look into this issue and, if I'm able, apply here some of the work done in my lib.
from objectbuffer.
Hey @emibcn :)
There's automatic self-benchmarks on each PR:
#146 (comment)
For various factors, IMO we can't effectively compare this library to native js objects.
Anyhow, I would love to collaborate about this topic!
I think that the "free shape" + automatic memory reclaim brings many difficulties
I will throw in some of the challenges to make fast props, or cheap objects:
We will need to have an objects shape registry, a way to compute object registry, and a cheap way to search the registry to see if this share is already exists.
(every shape will need to have reference count so we know when we can re claim it)
And a very painful code path that we will must have is, when object shape changes, we will need to turn it into slow object, or assign it a new shape.
All that is a lot of code, with unclear performance benefits (yet)
from objectbuffer.
I think that the "free shape" + automatic memory reclaim brings many difficulties
Me too. This is why I did mine without automatic memory and fixed shape 😜 Well, not only because of complexity, but also versatility. And maybe this would be a solution: let the user decide how to manage the object via some parameters:
We will need to have an objects shape registry, a way to compute object registry, and a cheap way to search the registry to see if this share is already exists.
(every shape will need to have reference count so we know when we can re claim it)
This is going to be a JS re-programming, but using JS itself, which performance is not always as expected. Have you considered adding some WASM to this project?
And a very painful code path that we will must have is, when object shape changes, we will need to turn it into slow object, or assign it a new shape.
Here is when we can let the user decide, using some of the options as default: it's not the same to handle a bunch of objects changing very fast than millions of objects rarely changing.
All that is a lot of code, with unclear performance benefits (yet)
I have taken several dead-end paths because of performance. But I had lot of fun walking those paths ;)
from objectbuffer.
Hey @Bnaya ,
I know I'm late to the party, but I think I've figured out a way create very fast objects that are backed by buffers.
Essentially what you do is create classes on the fly via the unsafe Function constructor that maps key names to a particular offsets in a typed array via getters and setters.
Here's an example:
// your object definition
const def = {x: "num", y: "num"}
// create a class based on definition
const MyObject = Function(`return class MyBufferObject {
constructor() {
this._memory = new Float64Array(${Object.keys(def).length})
}
${Object.keys(def).map((key, offset) => {
const getter = `get ${key}() { return this._memory[${offset}] }`
const setter = `set ${key}(newValue) { this._memory[${offset}] = newValue }`
return getter + ";" + setter
}).join("\n")}
}
`)()
// now you can use it like a normal object
const obj = new MyObject()
obj.x = 2
obj.y = 5
const {x, y} = obj
console.log(x, y) // output: 2 5
From my benchmarking, objects created this way are just as fast as native objects.
Anyhow, I though I'd give you my two cents on the issue.
from objectbuffer.
@moomoolive thank you for the research!
The library supports dynamic object shape which means we can't ahead of time create fixed getters and settres, among other things.
from objectbuffer.
Fair enough! This approach wouldn't really work with dynamic objects.
PS this library is such a good idea - I really hope js supports something like this out of the box in the future
from objectbuffer.
Related Issues (20)
- [Optimizations] In hashmap creation don't check if key already exists in bucket
- Add more benchmarks to CI
- Global string dedup cache
- Why does Node.js not provide something like SharedObjectBuffers out of the box? HOT 4
- look for v8 deopts
- Data structures notes [WIP]
- Allocator changes working plan HOT 1
- Near-term work plan
- [Feat]Iterative/non-blocking memory reclaim
- [Feat]Remove the class wrapper on top of the functional allocator
- [Feat]Find and refactor-out closures
- Explore thread-safe lock-free data structures using atomics
- Track resizablearraybuffer proposal [Stage 3] HOT 2
- [BUG] Make not sense when i tried to get non-existent array index HOT 4
- Track structs - Fixed Layout Objects proposal [Stage 1]
- npm run browser-playground not working: SyntaxError: Cannot use import statement outside a module HOT 2
- Would it make sense to support WeakMaps? HOT 1
- RangeError: Start offset undefined is outside the bounds of the buffer HOT 3
- How to reliably estimate size without too much overhead? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objectbuffer.