Skip to content

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

bash
# 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 10

Flags for analyze

FlagDefaultDescription
--jsonrequiredPath to the --analyze-size JSON output
--baselinenonePath to a committed baseline JSON to diff against
--platformandroidTarget platform: android or ios
--top20Number of top packages to display

update-baseline

bash
dart run monorepo_toolkit size-analyzer update-baseline \
  --json build/app-size.json \
  --output size_baseline/android.json

Flags for update-baseline

FlagDefaultDescription
--jsonrequiredPath to the --analyze-size JSON output
--outputrequiredDestination path for the new baseline file

Baseline pattern

Baselines are committed to the repository at:

size_baseline/
├── android.json
└── ios.json

CI 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:

yaml
# 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 push

Optional SizeMetricsReporter

Implement SizeMetricsReporter to push size data to a custom metrics backend (Prometheus, Datadog, Grafana, etc.):

dart
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.

Built by Banua Coder