Skip to content

Commit eca0beb

Browse files
buenaflordenrase
andauthored
Measure Dart SDK size overhead (#2482) (#2579)
Co-authored-by: Denis Andrašec <[email protected]>
1 parent 2268383 commit eca0beb

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

.github/workflows/metrics.yml

+22
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,25 @@ jobs:
9191
config: ./metrics/metrics-${{ matrix.platform }}.yml
9292
sauce-user: ${{ secrets.SAUCE_USERNAME }}
9393
sauce-key: ${{ secrets.SAUCE_ACCESS_KEY }}
94+
95+
metrics-dart:
96+
name: Console
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v4
100+
- uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # [email protected]
101+
102+
- name: create dart sample apps
103+
working-directory: ./metrics
104+
run: ./prepare-dart.sh
105+
106+
- name: build dart sample apps
107+
working-directory: ./metrics
108+
run: ./build-dart.sh
109+
110+
- name: Set file diff max threshold
111+
run: echo "THRESHOLD=13100000" >> $GITHUB_ENV # 1,31 MB
112+
113+
- name: Compare executable size
114+
working-directory: ./metrics
115+
run: ./compare_sizes.sh perf_test_console_plain.bin perf_test_console_sentry.bin $THRESHOLD

metrics/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
perf-test-app*
2+
perf_test_console*

metrics/build-dart.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd perf_test_console_plain
5+
dart pub get
6+
cd ..
7+
dart compile exe perf_test_console_plain/bin/perf_test_console_plain.dart -o ./perf_test_console_plain.bin
8+
9+
cd perf_test_console_sentry
10+
dart pub get
11+
cd ..
12+
dart compile exe perf_test_console_sentry/bin/perf_test_console_sentry.dart -o ./perf_test_console_sentry.bin

metrics/compare_sizes.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Inputs: file1, file2, threshold
5+
FILE1=$1
6+
FILE2=$2
7+
THRESHOLD=$3
8+
9+
if [ ! -f "$FILE1" ]; then
10+
echo "File not found: $FILE1"
11+
exit 1
12+
fi
13+
14+
if [ ! -f "$FILE2" ]; then
15+
echo "File not found: $FILE2"
16+
exit 1
17+
fi
18+
19+
# Get sizes of files (Linux-compatible)
20+
SIZE1=$(stat --format=%s "$FILE1")
21+
SIZE2=$(stat --format=%s "$FILE2")
22+
23+
# Calculate absolute size difference
24+
SIZE_DIFF=$(( SIZE1 - SIZE2 ))
25+
SIZE_DIFF=${SIZE_DIFF#-} # Convert to absolute value
26+
27+
# Print results
28+
echo "File 1: $FILE1 (Size: $SIZE1 bytes)"
29+
echo "File 2: $FILE2 (Size: $SIZE2 bytes)"
30+
echo "Difference: $SIZE_DIFF bytes"
31+
32+
# Check if the size difference exceeds the threshold
33+
if [ "$SIZE_DIFF" -gt "$THRESHOLD" ]; then
34+
echo "ERROR: Size difference between $FILE1 and $FILE2 exceeds $THRESHOLD bytes!"
35+
exit 1
36+
else
37+
echo "SUCCESS: Size difference between $FILE1 and $FILE2 is within $THRESHOLD bytes."
38+
fi

metrics/prepare-dart.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
targetDir=$(
5+
cd $(dirname $0)
6+
pwd
7+
)
8+
[[ "$targetDir" != "" ]] || exit 1
9+
10+
dartCreate() {
11+
name=${1//-/_}
12+
dir=$targetDir/$1
13+
rm -rf $dir
14+
echo "::group::dart create $1"
15+
dart create -t console $name
16+
echo '::endgroup::'
17+
}
18+
19+
dartCreate 'perf_test_console_plain'
20+
dartCreate 'perf_test_console_sentry'
21+
22+
echo '::group::Patch perf_test_console_sentry'
23+
pubspec="$targetDir/perf_test_console_sentry/pubspec_overrides.yaml"
24+
echo "Adding dependencies to $pubspec"
25+
cat <<EOF >>"$pubspec"
26+
27+
dependency_overrides:
28+
sentry:
29+
path: ../../dart
30+
31+
EOF
32+
33+
fileToReplace="$targetDir/perf_test_console_sentry/bin/perf_test_console_sentry.dart"
34+
if [[ -f "$fileToReplace" ]]; then
35+
echo "Replacing $fileToReplace with new content"
36+
cat <<'NEW_FILE_CONTENT' >"$fileToReplace"
37+
import 'package:perf_test_console_sentry/perf_test_console_sentry.dart' as perf_test_console_sentry;
38+
import 'package:sentry/sentry.dart';
39+
40+
Future<void> main(List<String> arguments) async {
41+
await Sentry.init((options) {
42+
options.dsn = 'https://[email protected]/5428562';
43+
});
44+
45+
print('Hello world: ${perf_test_console_sentry.calculate()}!');
46+
}
47+
NEW_FILE_CONTENT
48+
else
49+
echo "Error: File $fileToReplace not found!"
50+
exit 1
51+
fi
52+
echo '::endgroup::'

0 commit comments

Comments
 (0)