Skip to content

Feat/issue 167 gas benchmarking#201

Open
uzochukwuV wants to merge 2 commits intorinafcode:mainfrom
uzochukwuV:feat/issue-167-gas-benchmarking
Open

Feat/issue 167 gas benchmarking#201
uzochukwuV wants to merge 2 commits intorinafcode:mainfrom
uzochukwuV:feat/issue-167-gas-benchmarking

Conversation

@uzochukwuV
Copy link
Copy Markdown

@uzochukwuV uzochukwuV commented Mar 28, 2026

Closes #167


Summary

  • Implements a comprehensive gas usage benchmarking suite for all TeachLink contract operations, addressing issue No Performance Benchmarking #167 (No Performance Benchmarking)
  • Adds automated CI/CD pipeline for performance regression detection on every PR
  • Establishes gas thresholds, baseline tracking, and regression detection policies

Changes

Gas Benchmark Tests (contracts/teachlink/tests/test_gas_benchmarks.rs)

  • 14 gas benchmark tests covering: initialize, add_validator, add_supported_chain, set_bridge_fee, read_queries, cache_compute, cache_hit, register_validator, mint_content_token, transfer_content_token, send_notification, create_audit_record, initialize_mobile_profile, and a regression report
  • Each test measures CPU instruction cost and asserts against a per-operation threshold
  • Gas measurement uses Soroban budget tracking

Thresholds & Baselines

  • gas_thresholds.json - Defines max instructions, memory bytes, and WASM size limits for every operation category (bridge, cache, consensus, tokenization, rewards, messaging, notifications, mobile, audit)
  • gas_baseline.json - Tracks baseline gas usage for regression comparison (10% critical, 5% warning)

CI/CD Automation (.github/workflows/performance.yml)

  • Runs on push to main and PRs touching contracts/**, gas_thresholds.json, or gas_baseline.json
  • Builds WASM binary and checks size against 300 KB threshold
  • Runs gas benchmarks and generates reports
  • Comments PR with benchmark results table
  • Fails on critical regressions

Supporting Scripts

  • scripts/run_gas_benchmarks.py - Parses benchmark output, compares with baseline, generates JSON reports
  • scripts/benchmark.sh - Local development benchmark runner with WASM size checks
  • testing/performance/benchmark_runner.rs - Extended with GasBenchmarkResult tracking, threshold comparison, and baseline diffing

Test Results

All 14 gas benchmarks pass with operations well within thresholds:

Operation Gas Used Threshold Status
initialize 2,001 500,000 PASS
add_validator 34,454 200,000 PASS
add_supported_chain 34,539 200,000 PASS
set_bridge_fee 31,969 150,000 PASS
read_queries_bundle 623 100,000 PASS
compute_and_cache_bridge_summary 44,510 1,500,000 PASS
get_cached_bridge_summary 0 200,000 PASS
register_validator 95,212 500,000 PASS
mint_content_token 130,186 600,000 PASS
transfer_content_token 50,761 500,000 PASS
send_notification 38,679 350,000 PASS
create_audit_record 46,691 400,000 PASS
initialize_mobile_profile 306,883 400,000 PASS

Acceptance Criteria

  • Implement performance benchmarking suite
  • Add gas usage benchmarks
  • Monitor performance over time (baseline tracking)
  • Set performance regression thresholds
  • Automate performance testing (GitHub Actions)

…timization (rinafcode#167)

- Add gas usage benchmarks for all contract operations (bridge, consensus, tokenization, notifications, audit, mobile platform)
- Implement gas regression thresholds with per-operation limits
- Add baseline tracking and regression detection (10% critical, 5% warning)
- Add GitHub Actions workflow for automated performance testing on PRs
- Add Python benchmark runner for CI/CD integration and report generation
- Add shell benchmark script for local development
- Extend Rust benchmark runner with gas tracking capabilities
- Export ContentType from lib.rs for test usage
- All 14 gas benchmark tests pass with operations well within thresholds
 Add gas usage benchmarks
 Monitor performance over time
 Set performance regression thresholds
 Automate performance testing
@github-actions
Copy link
Copy Markdown

⚠️ PR Title Format

Please update your PR title to follow the conventional commit format:

type(scope): description

Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert

Examples:

  • feat(contract): add learning reward distribution
  • fix(escrow): resolve timeout calculation bug
  • docs: update contributing guidelines

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown

🎉 Welcome to TeachLink, @uzochukwuV!

Thank you for your first contribution! A maintainer will review your PR soon.

While you wait:

  • Make sure all CI checks pass ✅
  • Review the PR checklist
  • Join our Discord to connect with the community

We appreciate your contribution to decentralized education! 🎓

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@uzochukwuV Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No Performance Benchmarking

1 participant