Skip to content

Commit

Permalink
wasm-size: Compare base..head in size measurements, and apply nightly…
Browse files Browse the repository at this point in the history
… optimizations. (#4682)
  • Loading branch information
Miguel Fernández authored Feb 1, 2024
1 parent 510b667 commit ddeb661
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/wasm-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
steps:
- name: Checkout base branch
uses: actions/checkout@v4
# with:
# ref: ${{ github.event.pull_request.base.sha }}
with:
ref: ${{ github.event.pull_request.base.sha }}

- uses: cachix/install-nix-action@v24
with:
Expand Down
18 changes: 13 additions & 5 deletions query-engine/query-engine-wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Call this script as `./build.sh <npm_version>`
set -euo pipefail

rustup default stable

OUT_VERSION="${1:-}"
OUT_NPM_NAME="@prisma/query-engine-wasm"
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
REPO_ROOT="$( cd "$( dirname "$CURRENT_DIR/../../../" )" >/dev/null 2>&1 && pwd )"

Expand Down Expand Up @@ -38,12 +38,20 @@ then
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
fi

echo "ℹ️ Configuring rust toolchain to use nightly and rust-src component"
rustup default nightly-2024-01-25
rustup target add wasm32-unknown-unknown
rustup component add rust-src --target wasm32-unknown-unknown


echo "Building query-engine-wasm using $WASM_BUILD_PROFILE profile"
CARGO_PROFILE_RELEASE_OPT_LEVEL="z" wasm-pack build "--$WASM_BUILD_PROFILE" --target $OUT_TARGET --out-dir "$OUT_FOLDER" --out-name query_engine
export RUSTFLAGS="-Zlocation-detail=none"
CARGO_PROFILE_RELEASE_OPT_LEVEL="z" wasm-pack build "--$WASM_BUILD_PROFILE" --target "$OUT_TARGET" --out-dir "$OUT_FOLDER" --out-name query_engine . \
-Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort

# wasm-opt pass
WASM_OPT_ARGS=(
"-Os" # execute size-focused optimization passes
"-Os" # execute size-focused optimization passes (-Oz actually increases size by 1KB)
"--vacuum" # removes obviously unneeded code
"--duplicate-function-elimination" # removes duplicate functions
"--duplicate-import-elimination" # removes duplicate imports
Expand Down Expand Up @@ -132,4 +140,4 @@ export * from "./${BG_FILE}";
EOF
}

enable_cf_in_bindings "query_engine.js"
enable_cf_in_bindings "query_engine.js"

0 comments on commit ddeb661

Please sign in to comment.