Skip to content

Commit

Permalink
Track file sizes (#3037)
Browse files Browse the repository at this point in the history
<!--
Open the PR up as a draft until you feel it is ready for a proper
review.

Do not make PR:s from your own `main` branch, as that makes it difficult
for reviewers to add their own fixes.

Add any improvements to the branch as new commits to make it easier for
reviewers to follow the progress. All commits will be squashed to a
single commit once the PR is merged into `main`.

Make sure you mention any issues that this PR closes in the description,
as well as any other related issues.

To get an auto-generated PR description you can put "copilot:summary" or
"copilot:walkthrough" anywhere.
-->

### What

Fixes #2511

- Adds `scripts/ci/sizes.py` for measuring and comparing file sizes
  - This works for any files, not just WASM files
- Use the new script in a new `reusable_track_size.yml` workflow
- Measures sizes of various files (`.wasm`, `.js`, demo `.rrd`), and
uploads the results to GCS
- Compares the results to `main` and posts a PR comment if the size
changed significantly (+10% or -10%)
- Builds file size graphs and pushes them to `gh-pages` on every commit
to `main`
- Also updated the PR description template to include links to benchmark
graphs and the new size graphs.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3037) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/3037)
- [Docs
preview](https://rerun.io/preview/pr%3Ajan%2Ftrack-wasm-size/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Ajan%2Ftrack-wasm-size/examples)
  • Loading branch information
jprochazk authored Aug 18, 2023
1 parent be7a031 commit d8495e0
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ To get an auto-generated PR description you can put "copilot:summary" or "copilo
- [PR Build Summary](https://build.rerun.io/pr/{{ pr.number }})
- [Docs preview](https://rerun.io/preview/{{ "pr:%s"|format(pr.branch)|encode_uri_component }}/docs)
- [Examples preview](https://rerun.io/preview/{{ "pr:%s"|format(pr.branch)|encode_uri_component }}/examples)
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
9 changes: 9 additions & 0 deletions .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ jobs:
SOURCE_LINK_COMMIT_OVERRIDE: ${{ github.event.pull_request.head.sha }}
secrets: inherit

track-sizes:
name: "Track Sizes"
needs: [build-web-demo]
uses: ./.github/workflows/reusable_track_size.yml
with:
CONCURRENCY: push-${{ github.ref_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
secrets: inherit

upload-web-demo:
name: "Upload Web Demo"
needs: [build-web-demo]
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/on_push_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ jobs:
MARK_PRERELEASE_FOR_MAINLINE: true
secrets: inherit

track-sizes:
name: "Track Sizes"
needs: [build-web-demo]
uses: ./.github/workflows/reusable_track_size.yml
with:
CONCURRENCY: push-${{ github.ref_name }}
secrets: inherit

build-linux:
needs: [checks]
name: "Linux: Build/Test Wheels"
Expand Down
156 changes: 156 additions & 0 deletions .github/workflows/reusable_track_size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: "Track Size"

on:
workflow_call:
inputs:
CONCURRENCY:
required: true
type: string
ADHOC_NAME:
required: false
type: string
default: ""
PR_NUMBER:
required: false
type: number

permissions:
contents: write
id-token: write
deployments: write
pull-requests: write

jobs:
track-sizes:
name: "Track Sizes"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Get context
id: context
run: |
echo "head_short_sha=$(echo ${{ github.sha }} | cut -c1-7)" >> "$GITHUB_OUTPUT"
if [ -n ${{ inputs.PR_NUMBER }} ]; then
base_short_sha=$(echo ${{ github.event.pull_request.base.sha }} | cut -c1-7)
else
base_short_sha=$short_sha
fi
echo "base_short_sha=$base_short_sha" >> "$GITHUB_OUTPUT"
- id: "auth"
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
with:
version: ">= 363.0.0"

- name: Download web_viewer
uses: actions/download-artifact@v3
with:
name: web_viewer
path: web_viewer

- name: Download web_demo
uses: actions/download-artifact@v3
with:
name: web_demo
path: web_demo

- name: Download base branch results
run: |
file_path="gs://rerun-builds/sizes/commit/${{ steps.context.outputs.base_short_sha }}/data.json"
if [ "$(gsutil -q stat $file_path ; echo $?)" = 0 ]; then
gsutil cp $file_path "/tmp/prev.json"
else
echo "[]" > "/tmp/prev.json"
fi
- name: Measure sizes
id: measure
shell: bash
run: |
entries=()
entries+=("Wasm:web_viewer/re_viewer_bg.wasm:MB")
entries+=("JS:web_viewer/re_viewer.js:KB")
for file in web_demo/examples/**/*.rrd; do
name=$(basename $(dirname "$file"))
entries+=("$name.rrd:$file:KB")
done
data=$(python3 scripts/ci/sizes.py measure "${entries[@]}")
echo "$data"
echo "$data" > "/tmp/data.json"
comparison=$(python3 scripts/ci/sizes.py compare --threshold=5 "/tmp/prev.json" "/tmp/data.json")
echo "$comparison"
{
echo 'comparison<<EOF'
echo "$comparison"
echo EOF
} >> "$GITHUB_OUTPUT"
if [ -n "$comparison" ]; then
echo "is_comparison_set=true" >> "$GITHUB_OUTPUT"
else
echo "is_comparison_set=false" >> "$GITHUB_OUTPUT"
fi
- name: Upload data to GCS (commit)
if: inputs.ADHOC_NAME == ''
uses: google-github-actions/upload-cloud-storage@v1
with:
path: /tmp/data.json
destination: "rerun-builds/sizes/commit/${{ steps.context.outputs.head_short_sha }}"

- name: Upload data to GCS (adhoc)
if: inputs.ADHOC_NAME != ''
uses: google-github-actions/upload-cloud-storage@v1
with:
path: /tmp/data.json
destination: "rerun-builds/sizes/adhoc/${{ inputs.ADHOC_NAME }}"

- name: Store benchmark result
# Only run on `main`
if: github.ref == 'refs/heads/main'
# https://github.com/benchmark-action/github-action-benchmark
uses: benchmark-action/github-action-benchmark@v1
with:
name: Sizes
tool: customSmallerIsBetter
output-file-path: /tmp/benchmark
github-token: ${{ secrets.GITHUB_TOKEN }}

# Show alert with commit on detecting possible size regression
comment-on-alert: true
alert-threshold: "110%"
fail-on-alert: false
comment-always: false

save-data-file: true
auto-push: true
gh-pages-branch: gh-pages
benchmark-data-dir-path: dev/sizes
max-items-in-chart: 30

- name: Create PR comment
if: inputs.PR_NUMBER != '' && steps.measure.outputs.is_comparison_set == 'true'
# https://github.com/mshick/add-pr-comment
uses: mshick/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
message: |
# Size changes
${{ steps.measure.outputs.comparison }}
Loading

0 comments on commit d8495e0

Please sign in to comment.