Severity: Important (performance)
Current sort:
// contract.rs:474
let mut inserted = false;
for j in 0..leads.len() {
if avg > scores.get(j).unwrap() {
leads.insert(j, lead.clone()); // O(n) per insert
scores.insert(j, avg);
inserted = true;
break;
}
}
For 100 submissions: ~10,000 Vec operations. For 1,000: 1M ops. Soroban resource fees scale with this — finalize for a popular hackathon could become prohibitively expensive or fail resource limits.
Fix
Collect into Vec, then use sort_by once with explicit tiebreaker (see related issue on stable sort).
Tests
- Benchmark 100 submissions before/after
- Verify ordering matches previous behavior on small inputs
Severity: Important (performance)
Current sort:
For 100 submissions: ~10,000 Vec operations. For 1,000: 1M ops. Soroban resource fees scale with this — finalize for a popular hackathon could become prohibitively expensive or fail resource limits.
Fix
Collect into Vec, then use
sort_byonce with explicit tiebreaker (see related issue on stable sort).Tests