From 9aa40887314f0501918d56abf8b50604e7f87dd8 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 3 Mar 2022 13:58:57 -0500 Subject: [PATCH] Oz again --- Cargo.toml | 2 +- build.sh | 8 +++++--- src/function.rs | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 198df76..c59bb3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ crate-type=["cdylib"] [profile.release] debug = false codegen-units = 1 -opt-level = "s" #optimize for size +opt-level = "z" #optimize for size lto = true strip = true diff --git a/build.sh b/build.sh index 762040d..a8cbf48 100755 --- a/build.sh +++ b/build.sh @@ -1,18 +1,20 @@ #!/bin/bash set -e -rm -fr tmp pkg | true #delete tmp folder if exists +rm -fr tmp | true +rm -fr pkg | true #apply optimizations via wasm-opt wasm_opt() { - wasm-opt -Os -o pkg/integral_site_bg_2.wasm pkg/integral_site_bg.wasm + wasm-opt -Oz -o pkg/integral_site_bg_2.wasm pkg/integral_site_bg.wasm mv pkg/integral_site_bg_2.wasm pkg/integral_site_bg.wasm } if test "$1" == "" || test "$1" == "release"; then wasm-pack build --target web --release --no-typescript + echo "Binary size (pre-wasm_opt): $(du -sb pkg/integral_site_bg.wasm)" wasm_opt #apply wasm optimizations - + echo "Binary size (pre-strip): $(du -sb pkg/integral_site_bg.wasm)" llvm-strip --strip-all pkg/integral_site_bg.wasm elif test "$1" == "debug"; then wasm-pack build --target web --debug --no-typescript diff --git a/src/function.rs b/src/function.rs index 654a8af..6e048fb 100644 --- a/src/function.rs +++ b/src/function.rs @@ -38,6 +38,7 @@ pub struct Function { sum: RiemannSum, } +// x^2 function, set here so we don't have to regenerate it every time a new function is made fn default_function(x: f64) -> f64 { x.powi(2) } impl Function {