feat: add leaderboard cache, performance benchmarks, and verify SSE cleanup
- Add 30s TTL leaderboard cache with invalidation on fight completion - Add scoreRound performance benchmark: 1000 rounds in <100ms - Add checkAnswer performance benchmark: 1000 checks in <50ms - Add adversarial regex backtracking test for checkAnswer - Verify SSE cleanup: connections, IP counters, spectator counts, event listeners all properly decremented in finally block on disconnect Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
7d9b8b1dbf
commit
4074ef94eb
@@ -326,3 +326,23 @@ describe('calculateTier', () => {
|
||||
expect(calculateTier(1900, 39)).toBe(5) // below Legend wins
|
||||
})
|
||||
})
|
||||
|
||||
describe('scoreRound performance', () => {
|
||||
it('completes 1000 rounds in under 100ms (<0.1ms each)', () => {
|
||||
const challenge = makeChallenge()
|
||||
const botA = { id: 'a1', name: 'AlphaBot' }
|
||||
const botB = { id: 'b1', name: 'BetaBot' }
|
||||
|
||||
const start = performance.now()
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
scoreRound(
|
||||
challenge, botA, botB,
|
||||
makeResponse('4', 200 + i),
|
||||
makeResponse('banana', 500 + i),
|
||||
null, i % 6, 0,
|
||||
)
|
||||
}
|
||||
const elapsed = performance.now() - start
|
||||
expect(elapsed).toBeLessThan(100) // <0.1ms per call
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user