Repository navigation
Conversation
|
ptal @kdy1 |
|
Will do right away |
kdy1
left a comment
There was a problem hiding this comment.
Note
This text was drafted with AI and posted after human approval.
- Harness: T3 Code
- AI agents: Claude Opus 5.5 (claude-opus-5-5), review subagent GPT-6.2 Astra (gpt-6.2-astra), review subagent GPT-6.2 Sol (gpt-6.2-sol), review subagent Claude Opus 5.5 (claude-opus-5-5), review subagent Claude Sonnet 5.5 (claude-sonnet-5-5)
Thanks for the detailed write-up. I built the base and the head and compared them. The flag works as described. I have three inline comments and one more point below. I think the first inline comment (the new 16 MiB minimum) needs a decision before we merge, so I'm leaving this review as discussion points.
What I checked
-
I built both sides locally with the pinned toolchain (Rust 1.98.1, wasm-bindgen 0.2.100), not in the builder container. The memory section is
min: 24onmainandmin: 256on this PR. Neither side has a maximum. -
Node.js 24.22.1 (with spot checks on 26.13.1), one
transformSynccall in a new process:Input mainThis PR 1 KiB – 384 KiB of typed declarations, strip-onlyandtransform24 → 25–237 pages, protector invalidated stays at 256 pages, no invalidation 300 mixed calls (1–384 KiB) in one process grows, invalidated stays at 256 pages 2 MiB grows, invalidated grows, invalidated -
Load time and RSS after load did not change (about 56 MB on both sides).
-
npm testpasses on the head build (126/126). -
tools/config.tomldoes take effect.wasm-packruns cargo incrates/amaro, so--config ../../tools/config.tomlresolves. Neitherwasm-packnor the wasm-builder image setsRUSTFLAGS, so thetarget.*.rustflagssetting is not overridden.
Regression test (not in the diff)
No test checks the initial memory size. If a later build sets RUSTFLAGS, or stops passing --config ../../tools/config.toml, the module goes back to 24 pages. The build and all tests still pass in that case. A small test would catch this, for example test/wasm-memory.test.js:
const { test } = require("node:test");
const assert = require("node:assert");
const { __wasm } = require("../lib/wasm.js");
test("wasm memory starts at 16 MiB", () => {
assert.ok(__wasm.memory.buffer.byteLength >= 16 * 1024 * 1024);
});This test passed on the head build and failed on the main build.
I did not reproduce the 13–19% slowdown for a 512 KB source in a warm process. I did not test Node.js 22 or 27, Windows, macOS, or 32-bit platforms.
|
On the regression test: added as |
kdy1
left a comment
There was a problem hiding this comment.
Note
This text was drafted with AI and posted after human approval.
- Harness: T3 Code
- AI agents: Claude Opus 5.5 (claude-opus-5-5), review subagent GPT-6.2 Astra (gpt-6.2-astra), review subagent GPT-6.2 Sol (gpt-6.2-sol), review subagent Claude Opus 5.5 (claude-opus-5-5), review subagent Claude Sonnet 5.5 (claude-sonnet-5-5)
Thanks for the updates. The size figures and the isolate wording now match what I measured, and both new tests fail on a main build and pass on this branch.
I accept the 16 MiB load floor under --wasm-max-mem-pages that is documented in tools/config.toml.
I have two small inline comments.
kdy1
left a comment
There was a problem hiding this comment.
Note
This text was drafted with AI and posted after human approval.
- Harness: T3 Code
- AI agents: Claude Opus 5.5 (claude-opus-5-5), review subagent GPT-6.2 Astra (gpt-6.2-astra), review subagent GPT-6.2 Sol (gpt-6.2-sol), review subagent Claude Opus 5.5 (claude-opus-5-5), review subagent Claude Sonnet 5.5 (claude-sonnet-5-5)
Thanks for the updates. LGTM.
I checked the current head (d54f41a) against main:
- With the CI builds of both sides, sources of 1–256 KiB no longer grow the memory or invalidate the
ArrayBufferDetachingprotector, on Node.js 24 and 26. Larger sources still grow it, as the comment intools/config.tomlsays. - Both tests in
test/wasm-memory.test.jsfail on amainbuild and pass on this branch.npm testpasses (128/128). - The 16 MiB load floor under
--wasm-max-mem-pagesbehaves as documented: aRangeErrorat 255 pages, and the module loads at 256.
I have one optional wording suggestion inline.
|
Needs a rebase |
Growing the memory detaches its ArrayBuffer, which invalidates V8's ArrayBufferDetaching protector. Up to Node.js 26, any detach of a buffer that was read invalidates it. In 27, only a detach of a buffer with a DataView or with two views does, and the bindings hold a Uint8Array and a DataView of the memory's. Optimized code then checks every typed-array and DataView access for a detached buffer, in that V8 isolate, for the rest of its life. In Node.js 26.13.0, a loop that sums a Float64Array took 4 times as long after a 20 KB file had been stripped. The memory started at 24 pages (1.5 MiB) and grew for any source of more than 1 to 4 KB. Rust's allocator uses the initial memory before it grows the memory, so a linker flag is enough to give it more. With 256 pages, the source that I tested left the memory at its initial size up to 384 KB in strip-only mode, in transform mode, and in transform mode with a source map, and V8 printed no invalidation with --trace-protector-invalidation, in Node.js 22.23.5, 24.22.3, 26.13.0 and 27.0.0-alpha. At 512 KB it grew the memory to 265 pages. The size that fits depends on the source and on the options: of three other shapes of source, all left the memory at 256 pages up to 256 KB in every mode, and some grew it at 320 KB. Load time and resident memory didn't change, nor did the time to strip sources of 1 KB to 384 KB and of 1 MB to 4 MB. A 512 KB source took as long as before in a new process, and 13 to 19% longer (13.7 against 11.4 ms in 26.13.0) in a process that had stripped smaller sources many times. The protector is then invalidated after V8 has optimized the bindings, where it used to be invalidated before; with the protector invalidated at startup, the same strip took 11.4 ms. 16 MiB also becomes the least memory that the module loads with: V8 refuses to instantiate it under a lower --wasm-max-mem-pages than 256. A build that doesn't read tools/config.toml drops the linker flag without failing, so test/wasm-memory.test.js checks that the memory starts at exactly 16 MiB, and that a 64 KB source doesn't grow it. Refs: nodejs/node#67632 Signed-off-by: snovader <marcus.ording@hotmail.com>
d54f41a to
1f30991
Compare
|
Squashed into one commit, 1f30991 |
Stripping a TypeScript source of more than 1 to 4 KB grows amaro's WebAssembly memory. Growing detaches the memory's
ArrayBuffer, which invalidates V8'sArrayBufferDetachingprotector. Up to Node.js 26, any detach of a buffer that was read invalidates it. In 27, only a detach of a buffer with aDataViewor with two views does, and the wasm-bindgen bindings hold aUint8Arrayand aDataViewof the memory's. From then on, optimized code checks every typed-array andDataViewaccess for a detached buffer, in every module of that V8 isolate, for the rest of its life. In Node.js 26.13.0, a loop that sums aFloat64Arraytook 4 times as long after a 20 KB file had been stripped. nodejs/node#67632 has the details.This starts the memory at 256 pages (16 MiB) instead of 24, with a linker flag. Rust's allocator uses the initial memory before it grows the memory, so no code changes.
Results
Node.js 22.23.5, 24.22.3, 26.13.0 and 27.0.0-alpha, Apple M2 Pro, built with
wasm-packon macOS (not in the builder container).--trace-protector-invalidationprinted nothing. At 512 KB it grew the memory to 265 pages and invalidated the protector, as every source over a few KB does today.a as T;repeated: to 319 pages in strip-only mode, and to 333 with a source map).main).main.npm testpasses in all four versions.Limits
16 MiB is a threshold, not a fix: a source too large for it still grows the memory. The size is a judgment call, and I'm happy to change it.
16 MiB also becomes the least memory that the module loads with. Under a
--wasm-max-mem-pagesbelow 256, V8 refuses to instantiate it (RangeErroratrequire), wheremainloads with 24 pages or more and fails only once a source needs more than the cap.For sources of any size, the bindings can call
WebAssembly.Memory.prototype.toResizableBuffer()where the engine has it, so that growing resizes the buffer in place. That needs a declared maximum and a line added bytools/patch-wasm.mjs. It is on a branch, on top of this change, if you'd like it as a follow-up:Refs: nodejs/node#67632