From b1c3615431c1ae90363f9f83d9cc57208150a017 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 14 Aug 2026 14:09:10 +0200 Subject: [PATCH] chore: Add script to show the sizes of futures (async Rust) (#8536) Add the script from https://github.com/chatmail/core/pull/8345/changes#r3696015000 with a few small tweaks TODO: Add to readme --- scripts/README.md | 4 ++++ scripts/future-sizes.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 scripts/future-sizes.sh diff --git a/scripts/README.md b/scripts/README.md index 8025a08dc..b04afd164 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -37,6 +37,10 @@ and an own build machine. - `android-rpc-server.sh` compiles binaries of `deltachat-rpc-server` using Android NDK. +- `future-sizes.sh` prints the sizes of the largest Futures. + This can be helpful because Async Rust can lead to huge futures, + increasing RAM usage and compilation times. + ## Triggering runs on the build machine locally (fast!) There is experimental support for triggering a remote Python or Rust test run diff --git a/scripts/future-sizes.sh b/scripts/future-sizes.sh new file mode 100755 index 000000000..133d77db1 --- /dev/null +++ b/scripts/future-sizes.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Report the largest async-fn futures using rustc's unstable -Zprint-type-sizes. +# +# Usage: scripts/future-sizes.sh [TOP_N] (default: 30) +# +# Uses a dedicated target dir so the normal build cache is untouched +# and repeated runs only recompile the core crate itself. + +TOP_N="${1:-30}" + +export CARGO_TARGET_DIR="target/type-sizes" +export RUSTFLAGS="-Zprint-type-sizes" +export RUSTC_BOOTSTRAP=1 + +# Warm the dependency cache so their output doesn't pollute the report later. +cargo check --locked --release -p deltachat >/dev/null + +# Recompile only the core crate (release) capture its type-size report. +cargo clean --locked --release -p deltachat +report="$CARGO_TARGET_DIR/type-sizes.txt" +if ! cargo check --locked --release -p deltachat >"$report"; then + tail -20 "$report" + exit 1 +fi + +sizes=$(rg '^print-type-size type: `\{async fn body of (.*)\(\)\}`: ([0-9]+) bytes' \ + -or '$2 $1' "$report" | sort -rn | uniq) +if [ -z "$sizes" ]; then + echo "error: no type-size output found, see $report" >&2 + exit 1 +fi + +echo "Largest async fn futures in deltachat (top $TOP_N, bytes):" +head -"$TOP_N" <<<"$sizes" + +echo +echo "Full report (all types, with per-field breakdown): $report"