diff --git a/default.nix b/default.nix index df894c39c76..9b5bba68d5b 100644 --- a/default.nix +++ b/default.nix @@ -85,6 +85,7 @@ let wasmtime rust-bindgen python3 + binaryen ] ++ pkgs.lib.optional pkgs.stdenv.isDarwin [ libiconv ]; diff --git a/rts/Makefile b/rts/Makefile index 2d6578c1171..cd825f7d9a3 100644 --- a/rts/Makefile +++ b/rts/Makefile @@ -3,6 +3,7 @@ SHELL:=bash -O globstar CLANG ?= clang-18 WASM_CLANG ?= clang-18 WASM_LD ?= wasm-ld-18 +WASM_OPT = wasm-opt # # We manually list all the .c files of libtommath that we care about. @@ -151,7 +152,7 @@ RTS_LL_64=$(CLANG) -cc1 -triple wasm64-unknown-emscripten -emit-obj \ -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr \ -Wno-override-module RTS_LL_64_DEBUG=$(RTS_LL_64) -RTS_LL_64_RELEASE=$(RTS_LL_64) -O2 +RTS_LL_64_RELEASE=$(RTS_LL_64) -Oz # # Let make automatically search these directories (tommath and musl) for .c files @@ -266,7 +267,7 @@ $(TOMMATH_BINDINGS_RS_64): | _build/wasm64 RTS_DEPENDENCIES_32=$(TOMMATH_BINDINGS_RS_32) $(RTS_RUST_FILES) $(RTS_CARGO_FILES) | _build/wasm32 RTS_BUILD_32=cd motoko-rts && cargo build --target=wasm32-unknown-emscripten -Zbuild-std=core,alloc RTS_DEBUG_BUILD_32=$(RTS_BUILD_32) -RTS_RELEASE_BUILD_32=$(RTS_BUILD_32) --release +RTS_RELEASE_BUILD_32=$(RTS_BUILD_32) --release -Zbuild-std-features="panic_immediate_abort,optimize_for_size" RTS_DEBUG_TARGET_32=motoko-rts/target/wasm32-unknown-emscripten/debug/libmotoko_rts.a RTS_RELEASE_TARGET_32=motoko-rts/target/wasm32-unknown-emscripten/release/libmotoko_rts.a @@ -298,7 +299,7 @@ RTS_DEPENDENCIES_64=$(TOMMATH_BINDINGS_RS_64) $(RTS_RUST_FILES) $(RTS_CARGO_FILE COMPILER_FLAGS_64=--emit=llvm-ir RTS_BUILD_64=cd motoko-rts && RUSTFLAGS="${COMPILER_FLAGS_64}" cargo build --target=wasm64-unknown-unknown -Zbuild-std=core,alloc --features enhanced_orthogonal_persistence RTS_DEBUG_BUILD_64=$(RTS_BUILD_64) -RTS_RELEASE_BUILD_64=$(RTS_BUILD_64) --release +RTS_RELEASE_BUILD_64=$(RTS_BUILD_64) --release -Zbuild-std-features="panic_immediate_abort,optimize_for_size" RTS_DEBUG_TARGET_64_FOLDER=motoko-rts/target/wasm64-unknown-unknown/debug RTS_RELEASE_TARGET_64_FOLDER=motoko-rts/target/wasm64-unknown-unknown/release @@ -444,11 +445,13 @@ LINKER_OPTIONS_64=\ $(EXPORTED_SYMBOLS:%=--export=%) \ --whole-archive --experimental-pic +WASM_OPT_OPTIONS=-Oz mo-rts-non-incremental.wasm: $(RTS_RUST_NON_INCREMENTAL_WASM_32_A) $(WASM_A_DEPENDENCIES_32) $(WASM_LD) -o $@ \ $(LINKER_OPTIONS_32) \ $+ + $(WASM_OPT) $(WASM_OPT_OPTIONS) -o $@ $@ mo-rts-non-incremental-debug.wasm: $(RTS_RUST_NON_INCREMENTAL_DEBUG_WASM_32_A) $(WASM_A_DEPENDENCIES_32) $(WASM_LD) -o $@ \ @@ -459,6 +462,7 @@ mo-rts-incremental.wasm: $(RTS_RUST_INCREMENTAL_WASM_32_A) $(WASM_A_DEPENDENCIES $(WASM_LD) -o $@ \ $(LINKER_OPTIONS_32) \ $+ + $(WASM_OPT) $(WASM_OPT_OPTIONS) -o $@ $@ mo-rts-incremental-debug.wasm: $(RTS_RUST_INCREMENTAL_DEBUG_WASM_32_A) $(WASM_A_DEPENDENCIES_32) $(WASM_LD) -o $@ \ @@ -469,6 +473,7 @@ mo-rts-eop.wasm: $(RTS_RUST_WASM_64_A) $(CORE_WASM_64_A) $(ALLOC_WASM_64_A) $(CO $(WASM_LD) -o $@ \ $(LINKER_OPTIONS_64) \ $+ + $(WASM_OPT) $(WASM_OPT_OPTIONS) -o $@ $@ mo-rts-eop-debug.wasm: $(RTS_RUST_DEBUG_WASM_64_A) $(CORE_DEBUG_WASM_64_A) $(ALLOC_DEBUG_WASM_64_A) $(COMPILER_BUILTINS_DEBUG_WASM_64_A) $(WASM_A_DEPENDENCIES_64) $(WASM_LD) -o $@ \ diff --git a/rts/motoko-rts/Cargo.toml b/rts/motoko-rts/Cargo.toml index 1e29a0b5cd0..09f39072345 100644 --- a/rts/motoko-rts/Cargo.toml +++ b/rts/motoko-rts/Cargo.toml @@ -44,4 +44,4 @@ panic = "abort" [profile.release] panic = "abort" codegen-units = 1 # makes debugging easier -opt-level = "s" # optimize for size +opt-level = "z" # super-optimize for size diff --git a/test/bench/ok/alloc.drun-run.ok b/test/bench/ok/alloc.drun-run.ok index f4ae3aa77a9..87a3330c319 100644 --- a/test/bench/ok/alloc.drun-run.ok +++ b/test/bench/ok/alloc.drun-run.ok @@ -1,8 +1,8 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: (+268_435_456, 3_071_963_514) +debug.print: (+268_435_456, 3_071_992_198) ingress Completed: Reply: 0x4449444c0000 -debug.print: (+268_435_456, 3_070_505_338) +debug.print: (+268_435_456, 3_070_534_022) ingress Completed: Reply: 0x4449444c0000 -debug.print: (+268_435_456, 3_070_505_338) +debug.print: (+268_435_456, 3_070_534_022) ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/bignum.drun-run.ok b/test/bench/ok/bignum.drun-run.ok index a883c928749..8ed960768d8 100644 --- a/test/bench/ok/bignum.drun-run.ok +++ b/test/bench/ok/bignum.drun-run.ok @@ -1,6 +1,6 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: {cycles = 2_467_268; size = +59_652} +debug.print: {cycles = 2_508_947; size = +59_652} ingress Completed: Reply: 0x4449444c0000 -debug.print: {cycles = 105_698_659; size = +1_817_872} +debug.print: {cycles = 105_771_400; size = +1_817_872} ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/candid-subtype-cost.drun-run.ok b/test/bench/ok/candid-subtype-cost.drun-run.ok index 92c75d49179..c2d69ad296f 100644 --- a/test/bench/ok/candid-subtype-cost.drun-run.ok +++ b/test/bench/ok/candid-subtype-cost.drun-run.ok @@ -1,4 +1,4 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: {cycles = 941_951; heap_bytes = +12_564} +debug.print: {cycles = 1_035_990; heap_bytes = +12_564} ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/heap-32.drun-run.ok b/test/bench/ok/heap-32.drun-run.ok index 9eaf86b3290..2635bb3a87c 100644 --- a/test/bench/ok/heap-32.drun-run.ok +++ b/test/bench/ok/heap-32.drun-run.ok @@ -1,5 +1,5 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: (50_227, +29_863_068, 739_048_937) -debug.print: (50_070, +32_992_212, 803_211_842) +debug.print: (50_227, +29_863_068, 683_152_487) +debug.print: (50_070, +32_992_212, 742_929_436) ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/heap-64.drun-run.ok b/test/bench/ok/heap-64.drun-run.ok index fb2db91dfd5..16bebcce5ee 100644 --- a/test/bench/ok/heap-64.drun-run.ok +++ b/test/bench/ok/heap-64.drun-run.ok @@ -1,5 +1,5 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: (49_965, +47_942_744, 997_701_676) -debug.print: (49_806, +47_960_000, 1_006_736_486) +debug.print: (49_965, +47_942_744, 936_552_826) +debug.print: (49_806, +47_960_000, 944_655_592) ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/nat16.drun-run.ok b/test/bench/ok/nat16.drun-run.ok index 8febef52370..030796b7bef 100644 --- a/test/bench/ok/nat16.drun-run.ok +++ b/test/bench/ok/nat16.drun-run.ok @@ -1,4 +1,4 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: (0, 51_380_880) +debug.print: (0, 51_380_892) ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/palindrome.drun-run.ok b/test/bench/ok/palindrome.drun-run.ok index c4cbbeed192..53b2cdf7d0e 100644 --- a/test/bench/ok/palindrome.drun-run.ok +++ b/test/bench/ok/palindrome.drun-run.ok @@ -1,9 +1,9 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: (true, +1_188, 13_158) -debug.print: (false, +1_188, 12_207) -debug.print: (false, +1_188, 13_137) -debug.print: (true, +868, 13_266) -debug.print: (false, +868, 11_729) -debug.print: (false, +868, 13_214) +debug.print: (true, +1_188, 13_503) +debug.print: (false, +1_188, 12_552) +debug.print: (false, +1_188, 13_482) +debug.print: (true, +868, 13_611) +debug.print: (false, +868, 12_074) +debug.print: (false, +868, 13_559) ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/region-mem.drun-run.ok b/test/bench/ok/region-mem.drun-run.ok index efb2339ece9..8f9500fac01 100644 --- a/test/bench/ok/region-mem.drun-run.ok +++ b/test/bench/ok/region-mem.drun-run.ok @@ -1,4 +1,4 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: {heap_diff = 0; instr_diff = 5_939_134_825} +debug.print: {heap_diff = 0; instr_diff = 9_235_857_781} ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/region0-mem.drun-run.ok b/test/bench/ok/region0-mem.drun-run.ok index 8b763c2ea6f..5f25086b4e5 100644 --- a/test/bench/ok/region0-mem.drun-run.ok +++ b/test/bench/ok/region0-mem.drun-run.ok @@ -1,4 +1,4 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: {heap_diff = 0; instr_diff = 6_366_953_833} +debug.print: {heap_diff = 0; instr_diff = 9_663_676_789} ingress Completed: Reply: 0x4449444c0000 diff --git a/test/bench/ok/stable-mem.drun-run.ok b/test/bench/ok/stable-mem.drun-run.ok index 5e3eeec3bce..69f23a6f184 100644 --- a/test/bench/ok/stable-mem.drun-run.ok +++ b/test/bench/ok/stable-mem.drun-run.ok @@ -1,4 +1,4 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 ingress Completed: Reply: 0x4449444c0000 -debug.print: {heap_diff = 0; instr_diff = 3_875_537_257} +debug.print: {heap_diff = 0; instr_diff = 3_875_537_269} ingress Completed: Reply: 0x4449444c0000 diff --git a/test/run-drun/empty-actor-classical.mo b/test/run-drun/empty-actor-classical.mo index 3343abea28a..008e213b504 100644 --- a/test/run-drun/empty-actor-classical.mo +++ b/test/run-drun/empty-actor-classical.mo @@ -2,6 +2,4 @@ actor {}; // CHECK: (func $canister_init -// CHECK: call ${{copying_gc|compacting_gc|generational_gc|incremental_gc}} - // CHECK: (export "canister_init" (func $canister_init)) diff --git a/test/run-drun/empty-actor-enhanced.mo b/test/run-drun/empty-actor-enhanced.mo index b5be96391ef..fbc815c9754 100644 --- a/test/run-drun/empty-actor-enhanced.mo +++ b/test/run-drun/empty-actor-enhanced.mo @@ -2,14 +2,9 @@ actor {}; // CHECK: (func $@motoko_async_destabilization (type 0) -// CHECK: call $trans_state10 -// CHECK: call $post_exp -// CHECK: call $start_gc_after_destabilization -// CHECK: call $trans_state4 // CHECK: call $@initialize_main_actor // CHECK: (func $canister_init -// CHECK-NEXT: call $trans_state -// CHECK-NEXT: call $init +// CHECK: call $init // CHECK: (export "canister_init" (func $canister_init))