From 6450cd877096ad83bd5531c014301c8ae068c05f Mon Sep 17 00:00:00 2001 From: monosans Date: Mon, 2 Feb 2026 16:34:20 +0300 Subject: [PATCH] refactor(script): extract script content into a variable for cleaner docker run command --- .github/scripts/allocator_bench_alpine.sh | 75 ++++++++++++----------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/.github/scripts/allocator_bench_alpine.sh b/.github/scripts/allocator_bench_alpine.sh index cb6b3db..3c03935 100644 --- a/.github/scripts/allocator_bench_alpine.sh +++ b/.github/scripts/allocator_bench_alpine.sh @@ -6,47 +6,50 @@ if [[ "${TOKIO_MULTI_THREAD:-false}" == "true" ]]; then TOKIO_FEATURE="tokio-multi-thread" fi +ALPINE_SCRIPT=$(cat <<'EOF' +set -eu +apk add --no-cache build-base pkgconfig time + +build_features() { + allocator="$1" + features="" + if [ "$allocator" != "system" ]; then + features="$allocator" + fi + if [ -n "$TOKIO_FEATURE" ]; then + if [ -n "$features" ]; then + features="$features,$TOKIO_FEATURE" + else + features="$TOKIO_FEATURE" + fi + fi + echo "$features" +} + +: > /work/alpine-results.tsv +for allocator in system jemalloc mimalloc_v2 mimalloc_v3; do + features="$(build_features "$allocator")" + if [ -n "$features" ]; then + output="$(/usr/bin/time -v cargo run --release --locked --features "$features" 2>&1 >/dev/null)" + else + output="$(/usr/bin/time -v cargo run --release --locked 2>&1 >/dev/null)" + fi + peak="$(echo "$output" | awk -F': ' '/Maximum resident set size/ {print $2; exit}')" + if [ -z "$peak" ]; then + echo "Failed to parse peak memory for $allocator" >&2 + exit 1 + fi + printf "%s\t%s\n" "$allocator" "$peak" >> /work/alpine-results.tsv +done +EOF +) + docker run --rm \ -v "$PWD:/work" \ -w /work \ -e TOKIO_FEATURE="$TOKIO_FEATURE" \ -e PLATFORM_LABEL="${PLATFORM_LABEL:-unknown}" \ - rust:nightly-alpine sh -lc ' - set -eu - apk add --no-cache build-base pkgconfig time - - build_features() { - allocator="$1" - features="" - if [ "$allocator" != "system" ]; then - features="$allocator" - fi - if [ -n "$TOKIO_FEATURE" ]; then - if [ -n "$features" ]; then - features="$features,$TOKIO_FEATURE" - else - features="$TOKIO_FEATURE" - fi - fi - echo "$features" - } - - : > /work/alpine-results.tsv - for allocator in system jemalloc mimalloc_v2 mimalloc_v3; do - features="$(build_features "$allocator")" - if [ -n "$features" ]; then - output="$(/usr/bin/time -v cargo run --release --locked --features "$features" 2>&1 >/dev/null)" - else - output="$(/usr/bin/time -v cargo run --release --locked 2>&1 >/dev/null)" - fi - peak="$(echo "$output" | awk -F': ' '/Maximum resident set size/ {print $2; exit}')" - if [ -z "$peak" ]; then - echo "Failed to parse peak memory for $allocator" >&2 - exit 1 - fi - printf "%s\t%s\n" "$allocator" "$peak" >> /work/alpine-results.tsv - done - ' + rust:nightly-alpine sh -lc "$ALPINE_SCRIPT" { echo "### ${PLATFORM_LABEL:-unknown} (tokio-multi-thread=${TOKIO_MULTI_THREAD:-false})"