binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Support `Custom Page Sizes` proposal

Open vshymanskyy opened this issue 1 year ago • 3 comments

Currently, the WASM page size is fixed at 64KiB, which is rather expensive in some scenarios.

WebAssembly WG proposed a new feature to handle it nicely: https://github.com/WebAssembly/custom-page-sizes/blob/main/proposals/custom-page-sizes/Overview.md

It should be rather easy to implement, and it would help to catalyse the adoption of this feature: https://github.com/AssemblyScript/assemblyscript/issues/2866

vshymanskyy avatar Aug 25 '24 18:08 vshymanskyy

PRs for this would be very welcome.

tlively avatar Aug 27 '24 00:08 tlively

Hi. I am currently working on including support for this feature in a WebAssembly runtime for MCUs and therefore very interested in the compilation pipeline to WebAssembly supporting this feature. It is currently impossible to run wasm-opt to run extra-optimizations on my wasm module, if the linker generates a memory with a custom page size, so I have to choose now between less waste in the linear memory size and well-optimized wasm bitcode. I am not too familiar with the binaryen code base, but happy to contribute if you expect the implementation to be easy. What are the key tasks/ features to tacke for implementing such support?

BilelGho avatar Jun 23 '25 08:06 BilelGho

@BilelGho This should be fairly easy, but would require changes in various places:

  • You would add the page size as a property on the Memory class in wasm.h, replacing the constant kPageSize.
  • Find all the places in the codebase that use the constant page size kPageSize and make them use the new variable page size.
  • Add parsing and printing, in both text and binary.

kripken avatar Jun 23 '25 15:06 kripken