--disable-wasm-trap-handler


默认情况下,Node.js 启用了基于陷阱处理程序的 WebAssembly 边界检查。因此,V8 不需要在从 WebAssembly 编译的代码中插入内联边界检查,这可能显著加快 WebAssembly 的执行速度,但此优化需要分配一个大的虚拟内存区(当前为 10GB)。如果由于系统配置或硬件限制,Node.js 进程无法访问足够大的虚拟内存地址空间,用户将无法运行涉及在此虚拟内存区分配的任何 WebAssembly,并会看到内存不足的错误。

【By default, Node.js enables trap-handler-based WebAssembly bound checks. As a result, V8 does not need to insert inline bound checks int the code compiled from WebAssembly which may speedup WebAssembly execution significantly, but this optimization requires allocating a big virtual memory cage (currently 10GB). If the Node.js process does not have access to a large enough virtual memory address space due to system configurations or hardware limitations, users won't be able to run any WebAssembly that involves allocation in this virtual memory cage and will see an out-of-memory error.】

$ ulimit -v 5000000
$ node -p "new WebAssembly.Memory({ initial: 10, maximum: 100 });"
[eval]:1
new WebAssembly.Memory({ initial: 10, maximum: 100 });
^

RangeError: WebAssembly.Memory(): could not allocate memory
    at [eval]:1:1
    at runScriptInThisContext (node:internal/vm:209:10)
    at node:internal/process/execution:118:14
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:101:62)
    at evalScript (node:internal/process/execution:136:3)
    at node:internal/main/eval_string:49:3
 

--disable-wasm-trap-handler 禁用此优化,以便用户至少能够运行 WebAssembly(性能较低),当他们的 Node.js 进程可用的虚拟内存地址空间低于 V8 WebAssembly 内存隔离所需的空间时。