thi-ng / umbrella

⛱ Broadly scoped ecosystem & mono-repository of 199 TypeScript projects (and ~180 examples) for general purpose, functional, data driven development
https://thi.ng
Apache License 2.0
3.36k stars 149 forks source link

How does Malloc compare with Node Alloc? #335

Closed LifeIsStrange closed 2 years ago

LifeIsStrange commented 2 years ago

Hi :) I find th-ing Malloc to be a very interesting project! I recently stumbled upon https://nodejs.org/api/buffer.html#static-method-bufferallocunsafesize Node provide a "safe" and an "unsafe" Alloc method too, from a pool. I was wondering if you knew how does th-ing malloc compare e.g regarding performance with the Node allocator? :) Maybe you might mutually take optimizations/design inspirations from each other?

@postspectacular @Bnaya friendly ping

Bnaya commented 2 years ago

My 2 cents :) These are 2 different animals First, th-ing malloc can work in the browser or node, So there is not such thing "unsafe", unless you provide it a prev used arraybuffer. While with node buffer, you are actually getting some memory area from the operation system that you really don't know what's in there.

th-ing Malloc is a way to have virtual, smaller ArrayBuffers inside a single, bigger ArrayBuffer, which for some use-caes is more performant, While node buffer is a more capable version of an ArrayBuffer, Due to the fact It's Node specific api and not available in the browser.

LifeIsStrange commented 2 years ago

While with node buffer, you are actually getting some memory area from the operation system that you really don't know what's in there.

wow a Node buffer is outside of the V8 VM sandboxed heap?

Thanks for the explanations :) still curious about benchmarks though :p

postspectacular commented 2 years ago

Sorry, just catching up with this now... Alas I've got zero experience with Node's direct allocation mechanism, so really cant comment. FWIW this project here was also more intended for browser use cases and some types of WASM interop, e.g. for sharing of WebGL buffers (but not only)