4 ms·
> Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation. How can this be possible? How can allocation via JavaScr
by georgerobinson 11y ago
> Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation.
How can this be possible? How can allocation via JavaScript (which I assume must call malloc underneath) be faster than just malloc in C++? Does Node have a slab allocator for buffers like the Linux kernel has for task structs, or are objects allocated on the heap on demand?
- Shorel 11y agoMalloc in C/C++ is not particularly fast. Java for example does object instantiation much faster. It's also common to replace malloc with an in house implementation for performance sensitive code.
- LamaOfRuin 11y agoMy guess is that it was previously implemented in nodejs C code instead of V8, and they switched the nodejs buffers to take advantage of V8 ArrayBuffers.
- phpnode 11y agoIt's not the allocation itself that's faster, it's faster because it avoids the overhead of crossing the C++ -> JS barrier