CI/dev: speed up model_generator.sh ~4.2x via seeded lockfiles and topological parallel waves (#3929)
What changed, and why it matters
This commit is a build-script performance improvement. It speeds up the Flutter code-generation step in Cake Wallet's CI and developer tooling by running package builds in parallel waves and reusing dependency lockfiles. There is no user-facing change, no wallet logic change, and no security-relevant change.
No security action required. Treat as a normal CI/dev tooling optimization. Reviewers may optionally verify that parallel build_runner waves do not introduce non-deterministic generated outputs, but the commit explicitly preserves a single shared PUB_CACHE and deterministic pubspec.lock seeding.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors model_generator.sh and related GitHub Actions to reduce model-generation time. Key changes: (1) seed missing cw_*/pubspec.lock from the root pubspec.lock to avoid redundant git fetches, (2) run dart run build_runner build in dependency-ordered waves with configurable concurrency (-j), (3) add a cleanup trap and slot-based wait logic, and (4) update CI callers to pass -j 4 or -j 8. The script still performs flutter pub get serially before parallel waves and keeps a single shared PUB_CACHE. No cryptographic, networking, parsing, or secret-handling code is modified.
Changed components
model_generator.sh.github/workflows/pr_test_build_ios.yml.github/workflows/pr_test_build_linux.yml.github/workflows/reusable-build.yml.github/workflows/reusable-integration-test.ymlscripts/ci/ios_sim_build.shInspect captured patch +70 / −36
### .github/workflows/pr_test_build_ios.yml
@@ -284,7 +284,7 @@ jobs:
popd
- name: Build generated code
- run: ./model_generator.sh
+ run: ./model_generator.sh -j 4
- name: Generate localization
run: dart run tool/generate_localization.dart
### .github/workflows/pr_test_build_linux.yml
@@ -289,7 +289,7 @@ jobs:
- name: Build generated code
run: |
- ./model_generator.sh
+ ./model_generator.sh -j 8
- name: Generate localization
run: |
@@ -376,7 +376,7 @@ jobs:
- name: Build generated code
run: |
- ./model_generator.sh
+ ./model_generator.sh -j 8
- name: Generate localization
run: |
### .github/workflows/reusable-build.yml
@@ -340,7 +340,7 @@ jobs:
- name: Build generated code
run: |
- ./model_generator.sh
+ ./model_generator.sh -j 8
- name: Generate key properties
run: |
### .github/workflows/reusable-integration-test.yml
@@ -223,7 +223,7 @@ jobs:
- name: Build generated code
run: |
flutter --version
- ./model_generator.sh
+ ./model_generator.sh -j 4
- name: Generate KeyStore
run: |
### model_generator.sh
@@ -1,45 +1,79 @@
#!/bin/bash
set -x -e
-pids=()
+JOBS=1
+while getopts ":j:" opt; do
+ case "$opt" in
+ j) JOBS="$OPTARG" ;;
+ *) echo "Usage: $0 [-j N]" >&2; exit 2 ;;
+ esac
+done
+shift $((OPTIND - 1))
+if [[ "${1:-}" == "async" ]]; then
+ JOBS=4
+fi
+[[ "$JOBS" =~ ^[1-9][0-9]*$ ]] || { echo "Error: -j must be a positive integer (got '$JOBS')" >&2; exit 2; }
+
+cleanup() {
+ local pids
+ pids=$(jobs -rp)
+ if [[ -n "$pids" ]]; then
+ # shellcheck disable=SC2086
+ kill $pids 2>/dev/null || true
+ fi
+}
+trap cleanup EXIT
build_models() {
dart run build_runner build || {
dart run build_runner clean
dart run build_runner build
}
}
-export -f build_models
-
-for cwcoin in cw_{core,evm,monero,bitcoin,nano,bitcoin_cash,solana,tron,wownero,zano,decred,dogecoin,zcash}
-do
- if [[ "x$1" == "xasync" ]];
- then
- env PUB_CACHE=$HOME/.cache/pub-cache-$cwcoin bash -c "cd $cwcoin; flutter pub get; build_models; cd .." &
- pids+=($!)
- else
- cd $cwcoin; flutter pub get; build_models; cd ..
- fi
-done
-for cwcoin in cw_mweb;
-do
- if [[ "x$1" == "xasync" ]];
- then
- bash -c "cd $cwcoin; flutter pub get; cd .." &
- pids+=($!)
- else
- cd $cwcoin; flutter pub get; cd ..
- fi
-done
-for pid in "${pids[@]}"; do
- if ! wait "$pid"; then
- ec=$?
- echo "Error: Failed to generate models: $ec"
- exit $ec
+pub_get() {
+ flutter pub get --offline || flutter pub get
+}
+
+wait_slot() {
+ { set +x; } 2>/dev/null
+ while (( $(jobs -rp | wc -l) >= JOBS )); do
+ sleep 0.2
+ done
+ set -x
+}
+
+run_wave() {
+ local pids=() cwcoin pid ec
+ for cwcoin in "$@"; do
+ if (( JOBS == 1 )); then
+ (cd "$cwcoin" && build_models)
+ else
+ wait_slot
+ (cd "$cwcoin" && build_models) &
+ pids+=($!)
+ fi
+ done
+ for pid in "${pids[@]}"; do
+ wait "$pid" || { ec=$?; echo "Error: Failed to generate models: $ec" >&2; exit "$ec"; }
+ done
+}
+
+# Seed missing subpackage pubspec.lock from root so pub reuses locked git SHAs
+# instead of re-fetching ~195 git repos per subpackage; keep pub get serial so
+# concurrent runs never race on PUB_CACHE git locks.
+for cwcoin in cw_{mweb,core,evm,monero,bitcoin,nano,bitcoin_cash,solana,tron,wownero,zano,decred,dogecoin,zcash}; do
+ if [[ ! -f "$cwcoin/pubspec.lock" && -f pubspec.lock ]]; then
+ cp pubspec.lock "$cwcoin/pubspec.lock"
fi
+ (cd "$cwcoin" && pub_get)
done
-flutter pub get
+# Run build_runner in topological waves (cw_core first; cw_bitcoin_cash & cw_dogecoin depend on cw_bitcoin).
+run_wave cw_core
+run_wave cw_{evm,monero,bitcoin,nano,solana,tron,wownero,zano,decred,zcash}
+run_wave cw_{bitcoin_cash,dogecoin}
+
+pub_get
build_models
-flutter pub get
+pub_get
### scripts/ci/ios_sim_build.sh
@@ -88,7 +88,7 @@ for k in nano2ApiKey nanoNowNodesApiKey; do add_secret cw_nano/lib/.secrets.g.da
for k in tronGridApiKey tronNowNodesApiKey; do add_secret cw_tron/lib/.secrets.g.dart "$k"; done
add_secret cw_bitcoin/lib/.secrets.g.dart breezApiKey
flutter pub get
-./model_generator.sh
+./model_generator.sh -j 4
dart run tool/generate_localization.dart
./compile_graphics.sh
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.