mirror of
https://github.com/chatmail/core.git
synced 2026-09-22 13:01:21 +03:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
39
scripts/future-sizes.sh
Executable file
39
scripts/future-sizes.sh
Executable file
@@ -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"
|
||||
Reference in New Issue
Block a user