Skip to main content

WASM_MAX_STACK

Constant WASM_MAX_STACK 

Source
pub const WASM_MAX_STACK: u32 = _ /* 262_144u32 */;
Expand description

The largest ValidateOptions::max_stack on WebAssembly, and its default there (DEFAULT_MAX_STACK): 256 KiB.

The native stack of a JavaScript engine can run out before the module’s stack in linear memory reaches ValidateOptions::max_stack (see WASM_MAX_DEPTH). Measured with the npm package, the largest max_stack, in KiB, with which a recursion still ends with Error::Limit (LimitExceeded::Stack) rather than with the engine’s stack overflow, for the stylesheets of the built-in rule sets and of Peppol BIS Billing 3.0.22 on a document 8192 levels deep / a named template calling itself (not as a tail call) / a template rule applying itself / a function calling itself:

EngineOfficialNamed templateTemplate ruleFunction
Chrome 154, Web Worker320342348543
Chrome 154, main thread522512545863
Firefox 153, Web Worker6306746891021
Firefox 153, main thread1021102110211021
Node.js 226406796851021

(1021 KiB is the module’s own stack, 1 MiB, running out.) 256 KiB keeps a margin of a fifth below the smallest, a Chrome Web Worker.