Skip to content

Implement binary size tracker for OpShin contracts#521

Merged
nielstron merged 7 commits intodevfrom
copilot/fix-520
Sep 17, 2025
Merged

Implement binary size tracker for OpShin contracts#521
nielstron merged 7 commits intodevfrom
copilot/fix-520

Conversation

Copy link
Contributor

Copilot AI commented Sep 17, 2025

This PR implements a comprehensive binary size tracking system to monitor changes in compiled contract sizes across different optimization levels, helping detect regressions that could impact deployment costs and execution limits.

Problem

Occasionally, changes to the OpShin compiler significantly increase binary size, especially under >O2 optimization settings. This can be a huge issue for contract deployment costs and execution limits on Cardano.

Solution

The implementation provides automated tracking of binary sizes for representative contracts:

  • Baseline Generation: Creates size baselines from release artifacts that are stored as GitHub release assets
  • PR Checks: Automatically compares current branch against latest release baseline on every PR
  • Multiple Optimization Levels: Tests O1, O2, and O3 to catch optimization-specific regressions
  • Configurable Thresholds: 5% warning threshold, 10% significant change threshold
  • Developer Tools: Local checking tools for development workflow

Key Components

Scripts

  • scripts/binary_size_tracker.py - Main tracking script that compiles contracts and measures CBOR sizes
  • scripts/check_binary_sizes.py - Developer convenience tool for local testing against latest release
  • scripts/binary_size_config.yaml - Configuration for tracked contracts and thresholds

CI Integration

  • .github/workflows/binary-size-tracker.yml - PR workflow that downloads baselines and reports changes
  • Updated .github/workflows/release.yml - Generates and uploads baselines for new releases

Tracked Contracts

  • assert_sum - Simple spending validator (4.6KB)
  • marketplace - Complex contract with data structures (8.9KB)
  • gift - Simple gift contract (1.7KB)
  • dual_use - Multi-purpose contract (0.6KB)

Example Output

Contract: marketplace
Description: Marketplace contract with complex data structures
----------------------------------------
  O1: 8,876 → 9,200 bytes (+324 bytes, +3.6%)
  O2: 8,868 → 9,100 bytes (+232 bytes, +2.6%) ⚠️
  O3: 8,868 → 9,500 bytes (+632 bytes, +7.1%) ⚠️

Total size change across all contracts: +1,188 bytes
⚠️ SIGNIFICANT BINARY SIZE CHANGES DETECTED

Usage

Developers can check their changes locally:

python scripts/check_binary_sizes.py

The system automatically runs on PRs and comments with size comparison reports, failing CI if changes exceed the significant threshold.

Fixes #520.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Sep 17, 2025

@nielstron 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits September 17, 2025 07:24
Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Copilot AI changed the title [WIP] Binary size tracker Implement binary size tracker for OpShin contracts Sep 17, 2025
Copilot AI requested a review from nielstron September 17, 2025 07:27
@github-actions
Copy link

github-actions bot commented Sep 17, 2025

✅ Binary Size Check Passed

Binary Size Comparison Report
Loading baseline measurements...
Measuring current binary sizes...
Measuring assert_sum...
  O0: 35042 bytes
  O1: 4604 bytes
  O2: 4604 bytes
  O3: 4604 bytes
Measuring marketplace...
  O0: 40776 bytes
  O1: 8876 bytes
  O2: 8868 bytes
  O3: 8868 bytes
Measuring gift...
  O0: 19472 bytes
  O1: 1652 bytes
  O2: 1652 bytes
  O3: 1652 bytes
Measuring wrapped_token...
  O0: 28516 bytes
  O1: 9522 bytes
  O2: 9256 bytes
  O3: 9256 bytes
Measuring micropayments...
  O0: 31900 bytes
  O1: 11192 bytes
  O2: 11174 bytes
  O3: 11174 bytes

============================================================
BINARY SIZE COMPARISON REPORT
============================================================

Contract: assert_sum
Description: Simple spending validator with assertion
----------------------------------------
  O0: 35,012 → 35,042 bytes (+30 bytes, +0.1%)
  O1: 4,604 → 4,604 bytes (+0 bytes, +0.0%)
  O2: 4,604 → 4,604 bytes (+0 bytes, +0.0%)
  O3: 4,604 → 4,604 bytes (+0 bytes, +0.0%)

Contract: marketplace
Description: Marketplace contract with complex data structures
----------------------------------------
  O0: 40,746 → 40,776 bytes (+30 bytes, +0.1%)
  O1: 8,876 → 8,876 bytes (+0 bytes, +0.0%)
  O2: 8,868 → 8,868 bytes (+0 bytes, +0.0%)
  O3: 8,868 → 8,868 bytes (+0 bytes, +0.0%)

Contract: gift
Description: Gift contract with simple logic
----------------------------------------
  O0: 19,442 → 19,472 bytes (+30 bytes, +0.2%)
  O1: 1,652 → 1,652 bytes (+0 bytes, +0.0%)
  O2: 1,652 → 1,652 bytes (+0 bytes, +0.0%)
  O3: 1,652 → 1,652 bytes (+0 bytes, +0.0%)

Contract: wrapped_token
Description: Dual-use contract to generate a wrapped token
----------------------------------------
  O0: 28,486 → 28,516 bytes (+30 bytes, +0.1%)
  O1: 9,522 → 9,522 bytes (+0 bytes, +0.0%)
  O2: 9,256 → 9,256 bytes (+0 bytes, +0.0%)
  O3: 9,256 → 9,256 bytes (+0 bytes, +0.0%)

Contract: micropayments
Description: Channel for fee-less micropayments
----------------------------------------
  O0: 31,872 → 31,900 bytes (+28 bytes, +0.1%)
  O1: 11,192 → 11,192 bytes (+0 bytes, +0.0%)
  O2: 11,174 → 11,174 bytes (+0 bytes, +0.0%)
  O3: 11,174 → 11,174 bytes (+0 bytes, +0.0%)

Total size change across all contracts: +148 bytes

✅ No significant binary size changes detected
============================================================

No significant binary size changes were detected in this PR.


This report compares the binary sizes of compiled contracts against the baseline from the latest release.

@coveralls
Copy link

coveralls commented Sep 17, 2025

Coverage Status

coverage: 91.6%. remained the same
when pulling 56d1a5e on copilot/fix-520
into 7885445 on dev.

@nielstron nielstron marked this pull request as ready for review September 17, 2025 09:01
@nielstron nielstron merged commit 7514663 into dev Sep 17, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binary size tracker

3 participants