Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measure Dart SDK size overhead #2482

Merged
merged 9 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,25 @@ jobs:
config: ./metrics/metrics-${{ matrix.platform }}.yml
sauce-user: ${{ secrets.SAUCE_USERNAME }}
sauce-key: ${{ secrets.SAUCE_ACCESS_KEY }}

metrics-dart:
name: Console
runs-on: macos-latest
denrase marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # [email protected]

- name: create dart sample apps
working-directory: ./metrics
run: ./prepare-dart.sh

- name: build dart sample apps
working-directory: ./metrics
run: ./build-dart.sh

- name: Set file diff max threshold
run: echo "THRESHOLD=13100000" >> $GITHUB_ENV # 1,31 MB

- name: Compare executable size
working-directory: ./metrics
run: ./compare_sizes.sh perf_test_console_plain.bin perf_test_console_sentry.bin $THRESHOLD
1 change: 1 addition & 0 deletions metrics/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
perf-test-app*
perf_test_console*
12 changes: 12 additions & 0 deletions metrics/build-dart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

cd perf_test_console_plain
dart pub get
cd ..
dart compile exe perf_test_console_plain/bin/perf_test_console_plain.dart -o ./perf_test_console_plain.bin

cd perf_test_console_sentry
dart pub get
cd ..
dart compile exe perf_test_console_sentry/bin/perf_test_console_sentry.dart -o ./perf_test_console_sentry.bin
38 changes: 38 additions & 0 deletions metrics/compare_sizes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -e

# Inputs: file1, file2, threshold
FILE1=$1
FILE2=$2
THRESHOLD=$3

if [ ! -f "$FILE1" ]; then
echo "File not found: $FILE1"
exit 1
fi

if [ ! -f "$FILE2" ]; then
echo "File not found: $FILE2"
exit 1
fi

# Get sizes of files (macOS-specific)
SIZE1=$(stat -f%z "$FILE1")
SIZE2=$(stat -f%z "$FILE2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be changed for linux


# Calculate absolute size difference
SIZE_DIFF=$(( SIZE1 - SIZE2 ))
SIZE_DIFF=${SIZE_DIFF#-} # Convert to absolute value

# Print results
echo "File 1: $FILE1 (Size: $SIZE1 bytes)"
echo "Binary 2: $FILE2 (Size: $SIZE2 bytes)"
echo "Difference: $SIZE_DIFF bytes"

# Check if the size difference exceeds the threshold
if [ "$SIZE_DIFF" -gt "$THRESHOLD" ]; then
echo "ERROR: Size difference between $FILE1 and $FILE2 exceeds $THRESHOLD bytes!"
exit 1
else
echo "SUCCESS: Size difference between $FILE1 and $FILE2 is within $THRESHOLD bytes."
fi
52 changes: 52 additions & 0 deletions metrics/prepare-dart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail

targetDir=$(
cd $(dirname $0)
pwd
)
[[ "$targetDir" != "" ]] || exit 1

dartCreate() {
name=${1//-/_}
dir=$targetDir/$1
rm -rf $dir
echo "::group::dart create $1"
dart create -t console $name
echo '::endgroup::'
}

dartCreate 'perf_test_console_plain'
dartCreate 'perf_test_console_sentry'

echo '::group::Patch perf_test_console_sentry'
pubspec="$targetDir/perf_test_console_sentry/pubspec_overrides.yaml"
echo "Adding dependencies to $pubspec"
cat <<EOF >>"$pubspec"

dependency_overrides:
sentry:
path: ../../dart

EOF

fileToReplace="$targetDir/perf_test_console_sentry/bin/perf_test_console_sentry.dart"
if [[ -f "$fileToReplace" ]]; then
echo "Replacing $fileToReplace with new content"
cat <<'NEW_FILE_CONTENT' >"$fileToReplace"
import 'package:perf_test_console_sentry/perf_test_console_sentry.dart' as perf_test_console_sentry;
import 'package:sentry/sentry.dart';

Future<void> main(List<String> arguments) async {
await Sentry.init((options) {
options.dsn = 'https://[email protected]/5428562';
});

print('Hello world: ${perf_test_console_sentry.calculate()}!');
}
NEW_FILE_CONTENT
else
echo "Error: File $fileToReplace not found!"
exit 1
fi
echo '::endgroup::'
Loading