Skip to content

Add runtime detection for toResizableBuffer. NFC#27096

Open
sbc100 wants to merge 2 commits into
emscripten-core:mainfrom
sbc100:toResizableBuffer
Open

Add runtime detection for toResizableBuffer. NFC#27096
sbc100 wants to merge 2 commits into
emscripten-core:mainfrom
sbc100:toResizableBuffer

Conversation

@sbc100

@sbc100 sbc100 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Since this is now shipping in the current version of all major browsers
we want to take advantage of it whenever possible.

I am leaving the GROWABLE_ARRAYBUFFERS setting in place for now since
enabling it unconditionally can still save a little on codesize but we
may want to to just remove that at some point.

As a side effect I think this might address #27084.

Since this is now shipping in the current version of all major browsers
we want to take advantage of it whenever possible.

I am leaving the GROWABLE_ARRAYBUFFERS setting in place for now since
enabling it unconditionally can still save a little on codesize but we
may want to to just remove that at some point.

As a side effect I think this might address emscripten-core#27084.
@kleisauke

Copy link
Copy Markdown
Collaborator

I am leaving the GROWABLE_ARRAYBUFFERS setting in place for now since
enabling it unconditionally can still save a little on codesize but we
may want to to just remove that at some point.

A nice thing about -sGROWABLE_ARRAYBUFFERS is that it also avoids the emscripten_notify_memory_growth(0) call that would otherwise be triggered each time Wasm memory grows.

#if !defined(EMSCRIPTEN_PURE_WASI)
// Success, update JS (see https://github.com/WebAssembly/WASI/issues/82)
emscripten_notify_memory_growth(0);
#endif

It also skips the -sSHARED_MEMORY acorn pass, which adds some overhead too.

// Instrument heap accesses to call growMemViews helper function, which allows
// pthreads + memory growth to work (we check if the memory was grown on another thread
// in each access), see #8365.
function growableHeap(ast) {

Thinking about this more, since -sGROWABLE_ARRAYBUFFERS is a link-time setting only, how about making the -sGROWABLE_ARRAYBUFFERS setting internally and applying it automatically when targeting modern environments? For example, it could be enabled when someone builds with -sENVIRONMENT=node -sMIN_NODE_VERSION=260000 or -sENVIRONMENT=web -sMIN_CHROME_VERSION=144 -sMIN_FIREFOX_VERSION=145 -sMIN_SAFARI_VERSION=260200.

Feature.GROWABLE_ARRAYBUFFERS: {
'chrome': 144,
'firefox': 145,
'safari': 260200,
# Supported with flag --experimental-wasm-rab-integration (TODO: Change
# this to unflagged version of Node.js 260000, see also the comment in
# Feature.WASM_EXCEPTIONS above)
'node': 240000,
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants