|
| 1 | +# CodSpeed Integration Setup Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document explains how to complete the CodSpeed.io integration for continuous performance monitoring of the `rslife` actuarial library. |
| 6 | + |
| 7 | +## What We've Set Up |
| 8 | + |
| 9 | +✅ **Criterion.rs with CodSpeed compatibility** - Added to `Cargo.toml` |
| 10 | +✅ **Comprehensive benchmark suite** - Created 3 benchmark files: |
| 11 | +- `benches/commutations.rs` - Commutation functions (Dx, Nx, Mx, Cx, Rx, Sx) |
| 12 | +- `benches/mortality_functions.rs` - Basic mortality functions (qx, lx, dx, px) |
| 13 | +- `benches/annuities.rs` - Annuity calculations and variations |
| 14 | + |
| 15 | +✅ **GitHub Actions workflow** - `.github/workflows/codspeed.yml` |
| 16 | + |
| 17 | +## Manual Steps Required |
| 18 | + |
| 19 | +### 1. Configure CodSpeed.io Account |
| 20 | + |
| 21 | +1. **Visit CodSpeed.io** |
| 22 | + ``` |
| 23 | + https://codspeed.io/ |
| 24 | + ``` |
| 25 | + |
| 26 | +2. **Sign up with GitHub** |
| 27 | + - Use your GitHub account to sign up |
| 28 | + - Grant necessary permissions |
| 29 | + |
| 30 | +3. **Connect your repository** |
| 31 | + - Add the `rslife` repository to CodSpeed |
| 32 | + - Follow the integration wizard |
| 33 | + |
| 34 | +4. **Generate API token** |
| 35 | + - Go to your CodSpeed dashboard |
| 36 | + - Navigate to Settings → Tokens |
| 37 | + - Generate a new token for `rslife` |
| 38 | + |
| 39 | +### 2. Add GitHub Secret |
| 40 | + |
| 41 | +1. Go to your GitHub repository: `https://github.com/hnlearndev/rslife` |
| 42 | +2. Navigate to **Settings** → **Secrets and variables** → **Actions** |
| 43 | +3. Click **New repository secret** |
| 44 | +4. Name: `CODSPEED_TOKEN` |
| 45 | +5. Value: Paste the token from CodSpeed.io |
| 46 | +6. Click **Add secret** |
| 47 | + |
| 48 | +### 3. Test the Setup |
| 49 | + |
| 50 | +Run benchmarks locally to verify everything works: |
| 51 | + |
| 52 | +```bash |
| 53 | +# Install dependencies |
| 54 | +cargo build |
| 55 | + |
| 56 | +# Run individual benchmark suites |
| 57 | +cargo bench --bench commutations |
| 58 | +cargo bench --bench mortality_functions |
| 59 | +cargo bench --bench annuities |
| 60 | + |
| 61 | +# Run all benchmarks |
| 62 | +cargo bench |
| 63 | +``` |
| 64 | + |
| 65 | +### 4. Verify CI Integration |
| 66 | + |
| 67 | +1. Create a test branch and make a small change |
| 68 | +2. Open a PR to main branch |
| 69 | +3. Check that CodSpeed workflow runs successfully |
| 70 | +4. Verify CodSpeed comments appear on the PR |
| 71 | + |
| 72 | +## Benchmark Coverage |
| 73 | + |
| 74 | +### Core Mathematical Functions |
| 75 | +- **Commutation Functions**: Dx, Nx, Mx, Cx, Rx, Sx with various scenarios |
| 76 | +- **Mortality Functions**: qx, lx, dx, px lookups and calculations |
| 77 | +- **Life Annuities**: Whole life, temporary, deferred variations |
| 78 | +- **Certain Annuities**: Fixed-period calculations |
| 79 | +- **Increasing Annuities**: Growing payment streams |
| 80 | + |
| 81 | +### Performance Scenarios |
| 82 | +- Single value calculations |
| 83 | +- Bulk operations (age ranges) |
| 84 | +- 1D vs 2D table operations |
| 85 | +- Different mortality tables (AM92, SULT) |
| 86 | +- Various interest rates and payment frequencies |
| 87 | +- Edge cases (young/old ages) |
| 88 | + |
| 89 | +### Data Loading Benchmarks |
| 90 | +- Mortality table loading from different sources |
| 91 | +- Configuration setup performance |
| 92 | + |
| 93 | +## Using CodSpeed Results |
| 94 | + |
| 95 | +### Interpreting Results |
| 96 | +- **Green indicators**: Performance maintained or improved |
| 97 | +- **Red indicators**: Performance regression detected |
| 98 | +- **Statistical significance**: CodSpeed uses rigorous statistical analysis |
| 99 | + |
| 100 | +### Performance Monitoring |
| 101 | +- Track trends over time in CodSpeed dashboard |
| 102 | +- Set up alerts for significant regressions |
| 103 | +- Compare performance across different actuarial scenarios |
| 104 | + |
| 105 | +### Optimization Workflow |
| 106 | +1. Make code changes |
| 107 | +2. Run benchmarks locally: `cargo bench` |
| 108 | +3. Check CodSpeed PR comments for performance impact |
| 109 | +4. Investigate any regressions before merging |
| 110 | + |
| 111 | +## Maintenance |
| 112 | + |
| 113 | +### Adding New Benchmarks |
| 114 | +When adding new actuarial functions: |
| 115 | + |
| 116 | +1. Add benchmark to appropriate file in `benches/` |
| 117 | +2. Follow existing patterns for setup and measurement |
| 118 | +3. Include realistic scenarios and edge cases |
| 119 | +4. Test locally before committing |
| 120 | + |
| 121 | +### Benchmark Best Practices |
| 122 | +- Use representative data (real mortality tables) |
| 123 | +- Cover common usage patterns |
| 124 | +- Include performance-critical code paths |
| 125 | +- Avoid I/O operations in benchmark loops |
| 126 | +- Use consistent test data across benchmarks |
| 127 | + |
| 128 | +## Troubleshooting |
| 129 | + |
| 130 | +### Common Issues |
| 131 | + |
| 132 | +**Benchmark compilation errors:** |
| 133 | +- Check that all imports in benchmark files are correct |
| 134 | +- Ensure CodSpeed dependencies are properly added |
| 135 | + |
| 136 | +**CodSpeed workflow failing:** |
| 137 | +- Verify `CODSPEED_TOKEN` secret is set correctly |
| 138 | +- Check GitHub Actions logs for specific errors |
| 139 | +- Ensure network access for mortality table downloads |
| 140 | + |
| 141 | +**Inconsistent results:** |
| 142 | +- CodSpeed uses statistical analysis to filter out noise |
| 143 | +- Local variations are normal; focus on CI results |
| 144 | +- Consistent regressions indicate real performance issues |
| 145 | + |
| 146 | +### Getting Help |
| 147 | +- CodSpeed documentation: https://docs.codspeed.io/ |
| 148 | +- Criterion.rs guide: https://bheisler.github.io/criterion.rs/ |
| 149 | +- GitHub Issues for this repository |
| 150 | + |
| 151 | +## Benefits for RSLife |
| 152 | + |
| 153 | +### Continuous Performance Monitoring |
| 154 | +- Automatic detection of performance regressions |
| 155 | +- Historical performance tracking |
| 156 | +- Statistical analysis to distinguish real changes from noise |
| 157 | + |
| 158 | +### Actuarial-Specific Value |
| 159 | +- **Mathematical Functions**: Monitor computational performance of complex actuarial calculations |
| 160 | +- **Data Processing**: Track efficiency of mortality table operations |
| 161 | +- **Scalability**: Ensure library performs well with various table sizes and calculation scenarios |
| 162 | + |
| 163 | +### Development Workflow |
| 164 | +- Performance feedback on every PR |
| 165 | +- Early detection of expensive changes |
| 166 | +- Data-driven optimization decisions |
| 167 | + |
| 168 | +## Next Steps |
| 169 | + |
| 170 | +1. Complete CodSpeed account setup |
| 171 | +2. Add `CODSPEED_TOKEN` to GitHub secrets |
| 172 | +3. Test with a sample PR |
| 173 | +4. Monitor performance trends |
| 174 | +5. Expand benchmark coverage as needed |
| 175 | + |
| 176 | +For questions about actuarial calculations or benchmark interpretation, refer to the main `README.md` and documentation. |
0 commit comments