Commit 55fd016
feat(benches): add benchmarks for historic and latest events scanning (#254)
<!-- Append the issue number -->
Related to #229
Hey!
This PR introduces a benchmarking system for Event Scanner using
**Criterion.rs** to measure performance impact of changes to the
scanner. Currently drafting, Bencher CI integration coming in follow-up.
---
### What's Included
#### New benches Crate Structure
```
benches/
├── Cargo.toml # Benchmark crate config
├── src/
│ └── lib.rs # Shared utilities (Anvil setup, contract deployment, event generation)
└── benches/
├── historic_scanning.rs # Historic mode benchmarks
└── latest_events_scanning.rs # Latest events mode benchmarks
```
#### Benchmarks Implemented
| Mode | Event Counts | What It Measures |
|------|--------------|------------------|
| **Historic** | 10K, 50K, 100K | Time to scan all events from block 0
to latest |
| **Latest Events** | 100, 1K, 10K, 50K | Time to fetch the N most
recent events from a 100K event pool |
example of Historic:
<img width="1186" height="623" alt="Screenshot 2025-12-13 at 2 58 25 PM"
src="https://github.com/user-attachments/assets/3fdcb55b-65bf-423a-8e02-d8005c943b51"
/>
---
### How Regression Testing Works
Criterion stores baseline results in
`target/criterion/<benchmark>/base/`. On subsequent runs, it compares
new measurements against this baseline and reports:
```
historic_scanning/events/10000
time: [30.963 ms 36.506 ms 40.598 ms]
thrpt: [246.32 Kelem/s 273.93 Kelem/s 322.97 Kelem/s]
change: [-2.12% -1.01% +0.12%] (p = 0.12 > 0.05)
No change in performance detected.
```
If a change introduces a regression, you'll see something like:
```
change: [+15.2% +18.4% +21.1%] (p = 0.00 < 0.05)
Performance has regressed.
```
This makes it easy to catch slowdowns before merging
---
### Running Benchmarks
```bash
# All benchmarks
cargo bench --manifest-path benches/Cargo.toml
# Specific benchmark
cargo bench --manifest-path benches/Cargo.toml --bench historic_scanning
cargo bench --manifest-path benches/Cargo.toml --bench latest_events_scanning
# Filter by event count
cargo bench --manifest-path benches/Cargo.toml -- "historic_scanning/events/10000"
```
---
### Next Steps
- **Bencher CI integration**: Add GitHub Actions workflow for on-demand
benchmarking with historical tracking via
[Bencher](https://bencher.dev/)
---------
Signed-off-by: yug49 <148035793+yug49@users.noreply.github.com>
Co-authored-by: Nenad <xinef.it@gmail.com>1 parent 9c8eff3 commit 55fd016
File tree
11 files changed
+1369
-20
lines changed- .github/workflows
- benches
- benches
- dumps
- src
- bin
11 files changed
+1369
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments