--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
禁用此优化,以便当 Node.js 进程可用的虚拟内存地址空间低于 V8 WebAssembly 内存笼所需的空间时,用户至少可以运行 WebAssembly(性能不太理想)。
¥--disable-wasm-trap-handler
disables this optimization so that
users can at least run WebAssembly (with less optimal performance)
when the virtual memory address space available to their Node.js
process is lower than what the V8 WebAssembly memory cage needs.