Size Analyzer Pro
The size-analyzer command parses the JSON output produced by flutter build --analyze-size and presents a ranked breakdown of the top contributors by size. It also diffs the current build against a committed baseline from the develop branch, surfacing regressions before they land.
Commands
analyze
# Analyze with no baseline (show top 20 packages)
dart run monorepo_toolkit size-analyzer analyze --json build/app-size.json
# Diff against a committed baseline
dart run monorepo_toolkit size-analyzer analyze \
--json build/app-size.json \
--baseline size_baseline/android.json \
--platform android
# Show top 10 instead of 20
dart run monorepo_toolkit size-analyzer analyze \
--json build/app-size.json \
--top 10Flags for analyze
| Flag | Default | Description |
|---|---|---|
--json | required | Path to the --analyze-size JSON output |
--baseline | none | Path to a committed baseline JSON to diff against |
--platform | android | Target platform: android or ios |
--top | 20 | Number of top packages to display |
update-baseline
dart run monorepo_toolkit size-analyzer update-baseline \
--json build/app-size.json \
--output size_baseline/android.jsonFlags for update-baseline
| Flag | Default | Description |
|---|---|---|
--json | required | Path to the --analyze-size JSON output |
--output | required | Destination path for the new baseline file |
Baseline pattern
Baselines are committed to the repository at:
size_baseline/
├── android.json
└── ios.jsonCI updates these files on every push to develop. PRs are then diffed against the most recent baseline, making size regressions visible before merge.
CI integration
Two-job pattern — analyze on PR, update baseline on develop merge:
# PR check job
- name: Analyze app size
run: |
flutter build apk --analyze-size --target-platform android-arm64
dart run monorepo_toolkit size-analyzer analyze \
--json build/flutter_size_*.json \
--baseline size_baseline/android.json \
--platform android
# Develop merge job (updates committed baseline)
- name: Update size baseline
if: github.ref == 'refs/heads/develop'
run: |
flutter build apk --analyze-size --target-platform android-arm64
dart run monorepo_toolkit size-analyzer update-baseline \
--json build/flutter_size_*.json \
--output size_baseline/android.json
git add size_baseline/android.json
git commit -m "chore: update android size baseline"
git pushOptional SizeMetricsReporter
Implement SizeMetricsReporter to push size data to a custom metrics backend (Prometheus, Datadog, Grafana, etc.):
import 'package:size_analyzer/size_analyzer.dart';
class DatadogSizeReporter implements SizeMetricsReporter {
@override
Future<void> report(List<SizeNode> nodes, String platform) async {
for (final node in nodes) {
await datadogClient.gauge(
'app.size.${platform}.${node.name}',
node.sizeBytes,
);
}
}
}Pass the reporter when invoking the analyzer programmatically, or register it via the config extension point generated in size_analyzer_service.dart.