arrayBuffer->Detach() in C++ has more overhead than it was expected to. #1266
Replies: 2 comments 8 replies
Lol. Well, yes. Rust, C, C++ are fast because they inherently do not have a GC. Go, Java, JavaScript, Haskell are slow because they are inherently designed around a GC. Proposing manual memory management for JavaScript is like proposing Atheism to be more like Islam. It's the wrong venue. |
Decision log — 2026-05-28Decisione: Motivazione: parity reference + DRY (discussion #36) + regola no-page-specific blocks (#77). Dettaglio: vedi commento in discussion #36 e STORY-062 nel mono. Owner: theme_sixteen (blade/CMS), module_geo (tickets.json/map-lit), module_fixcity (ViewModel filtri), module_cms (x-page breadcrumb). |
Uh oh!
There was an error while loading. Please reload this page.
I have recently finished creating 2 TC39 proposals on the way we handle network data in JavaScript - "JSON.parseBinary" and "ArrayBuffer.prototype.detach" (the one I am going to talk about now).
Both proposals contain benchmarks to make a solid background for the idea and "proposal-arraybuffer-detach" has an example with C++ V8 API and NAPI, where I call some js callback in a loop from C++, give it an ArrayBuffer over existing memory and detach that memory after the callback (or IN the callback). Just like uWebSockets.js does.
The nuance is that results do have a difference, which is unnoticeable at first.
What an AI suggest is that inside the callback "ArrayBuffer" as a param is kept hot in memory, but after callback - not. Also this is not just about speed, this is about immediately handling the memory you know you needn't after some parsing (gc-pressure test in that repo suggest that leaving GC handle all that memory comes at a huge cost).
What should you do with this?
So we can create new handlers or extend existing functionality to support manual memory management. Everything, obviously, has a sense of integrating only if at least "proposal-arraybuffer-detach" gets its deserved appraisal.
Btw, don't you mind me mentioning uWebSockets.js in my proposal?
It is already there in README, but this discussion is the first place where it goes to. Do you have any objections?
All reactions