Title: Type stripping invalidates V8's ArrayBufferDetaching protector, slowing typed-array code for the rest of the process · Issue #67632 · nodejs/node · GitHub
Open Graph Title: Type stripping invalidates V8's ArrayBufferDetaching protector, slowing typed-array code for the rest of the process · Issue #67632 · nodejs/node
X Title: Type stripping invalidates V8's ArrayBufferDetaching protector, slowing typed-array code for the rest of the process · Issue #67632 · nodejs/node
Description: Version v26.13.0 (V8 14.6.202.34-node.40, amaro 1.1.11) and v27.0.0-alpha (V8 15.6.75.25-node.10, amaro 1.1.11) Platform Darwin arm64 (Apple M2 Pro) Subsystem module, typescript (deps: amaro) What steps will reproduce the bug? Stripping ...
Open Graph Description: Version v26.13.0 (V8 14.6.202.34-node.40, amaro 1.1.11) and v27.0.0-alpha (V8 15.6.75.25-node.10, amaro 1.1.11) Platform Darwin arm64 (Apple M2 Pro) Subsystem module, typescript (deps: amaro) What ...
X Description: Version v26.13.0 (V8 14.6.202.34-node.40, amaro 1.1.11) and v27.0.0-alpha (V8 15.6.75.25-node.10, amaro 1.1.11) Platform Darwin arm64 (Apple M2 Pro) Subsystem module, typescript (deps: amaro) What ...
Opengraph URL: https://github.com/nodejs/node/issues/67632
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type stripping invalidates V8's ArrayBufferDetaching protector, slowing typed-array code for the rest of the process","articleBody":"### Version\n\nv26.13.0 (V8 14.6.202.34-node.40, amaro 1.1.11) and v27.0.0-alpha (V8 15.6.75.25-node.10, amaro 1.1.11)\n\n### Platform\n\n```text\nDarwin arm64 (Apple M2 Pro)\n```\n\n### Subsystem\n\nmodule, typescript (deps: amaro)\n\n### What steps will reproduce the bug?\n\nStripping the types of a TypeScript source of more than about 2 KB invalidates V8's `ArrayBufferDetaching` protector. Running a `.ts` file does it, and so does `module.stripTypeScriptTypes()`:\n\n```js\n// strip.mjs\nimport { stripTypeScriptTypes } from 'node:module';\n\nconst count = Number(process.argv[2]);\nlet source = '';\nfor (let i = 0; i \u003c count; i++) {\n source += `export function f${i}(a: number, b: number): number { return a + b; }\\n`;\n}\n\nstripTypeScriptTypes(source);\nconsole.log(`stripped ${source.length} bytes`);\n```\n\n```console\n$ node --no-warnings --trace-protector-invalidation strip.mjs 20\nstripped 1350 bytes\n$ node --no-warnings --trace-protector-invalidation strip.mjs 30\nInvalidating protector cell ArrayBufferDetaching\nstripped 2030 bytes\n```\n\nA 2.7 KB `.ts` entry point prints the same line, a 670-byte one doesn't, and the 2.7 KB file with its types removed by hand and saved as `.mjs` doesn't either.\n\nOnce the protector is invalid, optimized code checks typed-array accesses for detached buffers, in every module, until the process exits:\n\n```js\n// repro.mjs\n// node repro.mjs protector intact\n// node repro.mjs strip strips 20 KB of TypeScript first\nimport { stripTypeScriptTypes } from 'node:module';\n\nif (process.argv[2] === 'strip') {\n let source = '';\n for (let i = 0; i \u003c 300; i++) {\n source += `export function f${i}(a: number, b: number): number { return a + b; }\\n`;\n }\n stripTypeScriptTypes(source);\n}\n\nconst values = new Float64Array(1000).map((_, i) => i);\n\nfunction sum() {\n let total = 0;\n for (let i = 0; i \u003c values.length; i++) total += values[i];\n return total;\n}\n\nlet sink = 0;\nfor (let i = 0; i \u003c 200_000; i++) sink += sum();\n\nlet best = Infinity;\nfor (let round = 0; round \u003c 20; round++) {\n const start = process.hrtime.bigint();\n for (let i = 0; i \u003c 100_000; i++) sink += sum();\n best = Math.min(best, Number(process.hrtime.bigint() - start) / 100_000);\n}\n\nconsole.log(`${process.version} ${process.argv[2] ?? 'intact'}: ${best.toFixed(0)} ns per sum`);\n```\n\nFastest of 20 rounds, three processes each, on an M2 Pro:\n\n| Node | intact | after stripping | ratio |\n| --- | ---: | ---: | ---: |\n| 26.13.0 | 1438–1456 ns | 5753–5796 ns | 4.0× |\n| 27.0.0-alpha | 782–795 ns | 854–860 ns | 1.08× |\n\nIn Node 27 this loop loses less, but the protector is still invalidated, and larger code loses more: a binary format library's `DataView` getters, loaded from `.ts`, took about 1.6× as long in both versions as when a `module.registerHooks` load hook stripped the same files with a native transform. Having amaro strip a 300-function string at startup, with that hook still in place, brought the slowdown back.\n\n### How often does it reproduce? Is there a required condition?\n\nAlways, once one stripped source is large enough to grow amaro's WebAssembly memory. Most real `.ts` files are.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nRunning a program from `.ts` should leave typed-array code as fast as running the same program from `.js`. Type stripping is stable and on by default, so a process pays this whenever it loads a TypeScript file, whether or not it ever detaches a buffer itself.\n\n### What do you see instead?\n\n`Invalidating protector cell ArrayBufferDetaching`, and slower typed-array and `DataView` code for the rest of the process.\n\n### Additional information\n\n**Cause.** amaro is swc compiled to WebAssembly. When its memory grows, V8 detaches the `ArrayBuffer` that `memory.buffer` returned before. amaro's wasm-bindgen glue holds two views of that buffer (`deps/amaro/dist/internal.js`):\n\n```js\ncachedDataViewMemory0 = new DataView(wasm.memory.buffer)\ncachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer)\n```\n\n**Why V8 15 doesn't fix it.** V8 now tracks a buffer's view, so that detaching can mark that view instead of invalidating the protector ([crbug 467645277](https://issues.chromium.org/issues/467645277), [a08ad9c](https://github.com/v8/v8/commit/a08ad9c9c382b93980a7e76e65594a734cecadda), on by default since [2031231](https://github.com/v8/v8/commit/20312319d9), V8 15.x). It handles a buffer with no view or with one `TypedArray`. A buffer with two views, or with a `DataView`, still invalidates the protector (`JSArrayBuffer::TryDetachViews`), and amaro's memory has both. With `views.mjs` below:\n\n```js\n// node --trace-protector-invalidation views.mjs \u003cnone|one|two|dataview>\nconst mode = process.argv[2];\nconst memory = new WebAssembly.Memory({ initial: 1 });\nconst views = [];\nif (mode === 'none') memory.buffer;\nif (mode === 'one' || mode === 'two') views.push(new Uint8Array(memory.buffer));\nif (mode === 'two') views.push(new Uint8Array(memory.buffer));\nif (mode === 'dataview') views.push(new DataView(memory.buffer));\nmemory.grow(1);\n```\n\n| | none | one | two | dataview |\n| --- | --- | --- | --- | --- |\n| Node 26.13.0 | invalidated | invalidated | invalidated | invalidated |\n| Node 26.13.0 `--track-array-buffer-views` | intact | intact | invalidated | invalidated |\n| Node 27.0.0-alpha | intact | intact | invalidated | invalidated |\n\n**Possible fixes**, none of which I have tried in amaro itself:\n\n- Build amaro's WebAssembly module with enough initial memory that stripping ordinary files never grows it. This would help every release line, including those whose V8 doesn't track views.\n- Have the glue take its views from `memory.toResizableBuffer()`, which `memory.grow()` resizes instead of detaching. In both versions above, growing such a memory with a `Uint8Array` and a `DataView` on it left the protector intact.\n- Have the glue hold a single `Uint8Array` and no `DataView`. This helps only where V8 tracks views (15.x).\n\nI haven't run Node 24, or `main` with amaro 1.3.0, whose glue still creates both views.\n\nOther built-in paths invalidate the protector in Node 26.13.0: reading a `fetch` or `Response` body, constructing a `Blob` from a typed array, enqueuing into a byte stream, and `ArrayBuffer.prototype.transfer()`. In Node 27.0.0-alpha none of them does, so type stripping is the one built-in path I found that still invalidates it there. It also differs in kind: those are things a program does, while type stripping happens before the program's first line runs.\n","author":{"url":"https://github.com/snovader","@type":"Person","name":"snovader"},"datePublished":"2026-11-19T22:47:09Z","url":"https://github.com/nodejs/node/issues/67632"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:21575f00-a397-5174-495d-ba2ebc9e7166 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D5FA:14227A:35109E:476DF7:6B061979 |
| html-safe-nonce | 18da701bb8413a980d741b406934a645bd0ce78d249465d552a52bfd8d0958b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUZBOjE0MjI3QTozNTEwOUU6NDc2REY3OjZCMDYxOTc5IiwidmlzaXRvcl9pZCI6IjUxNzcwMzcxNTY3MTU0NjkxNzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 546d20ea79c5db8041329deff4e8b9007f26fffba9da90763cf9656736487946 |
| hovercard-subject-tag | issue:6500613652 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/67632/issue_layout |
| twitter:image | https://opengraph.githubassets.com/21860e848dba453c13af3661199e6268f80169a60116dc507aabaf693ffafb3a/nodejs/node/issues/67632 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/21860e848dba453c13af3661199e6268f80169a60116dc507aabaf693ffafb3a/nodejs/node/issues/67632 |
| og:image:alt | Version v26.13.0 (V8 14.6.202.34-node.40, amaro 1.1.11) and v27.0.0-alpha (V8 15.6.75.25-node.10, amaro 1.1.11) Platform Darwin arm64 (Apple M2 Pro) Subsystem module, typescript (deps: amaro) What ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | snovader |
| hostname | github.com |
| expected-hostname | github.com |
| None | 97d4714e567728e1f85f88b0cf68c89f0f8a3dc41e8869af7aeb8195ad990374 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 866f202ebf7ac5aff8f633417d9fd8a53818a977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width