-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make object faster maybe similar to https://v8.dev/blog/fast-properties #122
Comments
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 ( |
Hey @emibcn :) Anyhow, I would love to collaborate about this topic! 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:
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?
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.
I have taken several dead-end paths because of performance. But I had lot of fun walking those paths ;) |
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. |
@moomoolive thank you for the research! |
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 |
No description provided.
The text was updated successfully, but these errors were encountered: