rustwasm / team

A point of coordination for all things Rust and WebAssembly
MIT License
1.45k stars 59 forks source link

Rust allocates too many WASM pages again #218

Closed CryZe closed 6 years ago

CryZe commented 6 years ago

I'm doing a smaller Rust WASM project now and I've noticed that we are using at least 17 WASM pages again, even for a simple hello world project. That's 17 * 64 KiB = 1.1 MiB. That's quite a lot, considering not even a single page is fully used. Here's the text format of a small project:

(module
  (type $t0 (func (param i32 i32 i32) (result i32)))
  (type $t1 (func (param i32 i64)))
  (type $t2 (func))
  (import "env" "push_pointer_path" (func $push_pointer_path (type $t0)))
  (import "env" "push_offset" (func $push_offset (type $t1)))
  (func $__wasm_call_ctors (type $t2))
  (func $rust_eh_personality (type $t2))
  (func $configure (type $t2)
    (local $l0 i32)
    i32.const 1048576
    i32.const 12
    i32.const 8
    call $push_pointer_path
    tee_local $l0
    i64.const 0
    call $push_offset
    get_local $l0
    i64.const 1
    call $push_offset
    get_local $l0
    i64.const 2
    call $push_offset)
  (table $T0 1 1 anyfunc)
  (memory $memory 17)
  (global $g0 (mut i32) (i32.const 1048576))
  (global $__heap_base i32 (i32.const 1048588))
  (global $__data_end i32 (i32.const 1048588))
  (export "memory" (memory 0))
  (export "__heap_base" (global 1))
  (export "__data_end" (global 2))
  (export "rust_eh_personality" (func $rust_eh_personality))
  (export "configure" (func $configure))
  (data (i32.const 1048576) "explorer.exe"))

I think at some point we reduced this to only the amount that was necessary, but that doesn't seem to happen anymore.

CryZe commented 6 years ago

Urgh, nvm, I forgot that that's where the stack is and we are using 1 MiB now which is reasonable.