From 1c3377b22b43acb5b7231300897d29636b78dd02 Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Tue, 4 Oct 2022 02:37:50 +0200 Subject: [PATCH] chore: speedup wasm dev build Here for wasm dev build I replace the `wasm-pack` which is nice, but behind its defaults it hides lots of useful stuff, and I call `cargo build`, `wasm-bindgen` and `wasm-opt` explicitly. Notably `wasm-pack` does not allow custom cargo profiles (https://github.com/rustwasm/wasm-pack/issues/1111). I also add the new "opt-dev" cargo profile, which is something in the middle between `release` and `dev` - a balance between rebuild speed and runtime performance. This should save lots of time during day-to-day work. The production version still uses `wasm-pack` and a more tried solution. The dev version now requires cargo wasm toolchain, `wasm-bindgen` and `wasm-opt` (from `binaryen` project) installed manually. Previously `wasm-pack` would handle that. The dev docker image was updated accordingly. --- .cargo/config.toml | 27 ++++++++++++++++++++++++++ docker/docker-dev.dockerfile | 5 +++++ packages_rs/nextclade-web/package.json | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index e2c7ff48e..01addc37c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -22,6 +22,33 @@ opt-level = 3 [profile.dev.package.pretty_assertions] opt-level = 3 + +[profile.opt-dev] +inherits = "dev" +codegen-units = 128 +incremental = true +opt-level = 2 +lto = "off" +panic = "abort" +strip = true + +# Optimize dependencies even in debug mode +[profile.opt-dev.package."*"] +opt-level = 2 +[profile.opt-dev.package.backtrace] +opt-level = 3 +[profile.opt-dev.package.color-spantrace] +opt-level = 3 +[profile.opt-dev.package.tracing] +opt-level = 3 +[profile.opt-dev.package.tracing-error] +opt-level = 3 +[profile.opt-dev.package.tracing-subscriber] +opt-level = 3 +[profile.opt-dev.package.pretty_assertions] +opt-level = 3 + + [profile.release] codegen-units = 1 incremental = false diff --git a/docker/docker-dev.dockerfile b/docker/docker-dev.dockerfile index a8d13d4e5..6e1a13b5d 100644 --- a/docker/docker-dev.dockerfile +++ b/docker/docker-dev.dockerfile @@ -186,6 +186,11 @@ RUN set -euxo pipefail >/dev/null \ && curl -sSL "https://github.com/rustwasm/wasm-bindgen/releases/download/${WASM_BINDGEN_CLI_VERSION}/wasm-bindgen-${WASM_BINDGEN_CLI_VERSION}-x86_64-unknown-linux-musl.tar.gz" | tar -C "${CARGO_HOME}/bin" --strip-components=1 -xz "wasm-bindgen-${WASM_BINDGEN_CLI_VERSION}-x86_64-unknown-linux-musl/wasm-bindgen" \ && chmod +x "${CARGO_HOME}/bin/wasm-bindgen" +RUN set -euxo pipefail >/dev/null \ +&& export BINARYEN_VERSION="110" \ +&& curl -sSL "https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz" | tar -C "${CARGO_HOME}/bin" --strip-components=2 -xz "binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt" \ +&& chmod +x "${CARGO_HOME}/bin/wasm-opt" + # Install executable dependencies RUN set -euxo pipefail >/dev/null \ && cargo quickinstall cargo-audit \ diff --git a/packages_rs/nextclade-web/package.json b/packages_rs/nextclade-web/package.json index 253273d38..e8c2187f7 100644 --- a/packages_rs/nextclade-web/package.json +++ b/packages_rs/nextclade-web/package.json @@ -78,7 +78,7 @@ "monkey-patch": "bash tools/auspice-monkey-patch.sh && yarn run:node tools/monkeyPatch.ts", "changelog": "yarn conventional-changelog -p angular -i CHANGELOG.md -s -r 1", "serve-data": "babel-node --config-file \"./babel-node.config.js\" --extensions \".ts\" ./tools/server/dataServer.ts", - "wasm-dev": "wasm-pack --quiet --log-level=error build --dev --target=bundler --out-dir=.build/wasm-dev/ --out-name=nextclade-wasm -- --package=nextclade-web --locked && mkdir -p src/gen/ && cp .build/wasm-dev/* src/gen/", + "wasm-dev": "cargo build -q --profile=opt-dev --package=nextclade-web --lib --target=wasm32-unknown-unknown --target-dir=.build/docker/wasm-dev/ && wasm-bindgen .build/docker/wasm-dev/wasm32-unknown-unknown/opt-dev/nextclade_web.wasm --target=bundler --out-dir=.build/wasm-prod/ --out-name=nextclade-wasm && wasm-opt -O --optimize-level=1 --shrink-level=1 .build/docker/wasm-dev/wasm32-unknown-unknown/opt-dev/nextclade_web.wasm -o .build/wasm-prod/nextclade-wasm.wasm && mkdir -p src/gen/ && cp .build/wasm-prod/* src/gen/", "wasm-prod": "wasm-pack --quiet --log-level=error build --release --target=bundler --out-dir=.build/wasm-prod/ --out-name=nextclade-wasm -- --package=nextclade-web --locked && mkdir -p src/gen/ && cp .build/wasm-prod/* src/gen/" }, "dependencies": {