perf(arena): cut RPC polling load on the arena page#72
Merged
Conversation
useArenaEngine re-fetched immutable / slow-changing data on every 4s poll and kept polling in backgrounded tabs, so RPC load scaled linearly with the number of viewers and pegged the node during demos. Tier 1 (frontend-only, no behavior change): - Cache agent names (immutable after creation) — fetch once, not every poll - Skip getMatch for already-settled, fully-hydrated matches (immutable data) - Throttle tier-cooldown reads to 30s (the countdown ticks client-side) - Pause polling while the tab is hidden; re-pull on refocus - Poll interval 4s -> 8s Per active browser ~20.5 -> ~5 eth_call/s (~4x); backgrounded tabs -> 0. Live MatchSettled/MatchCreated subscriptions are unchanged, so fresh results still appear immediately. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
xmujx
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
演示时 ~10 人在线就把 Gravity RPC 节点 CPU 干到 800%。排查发现 arena 页的数据轮询(
useArenaEngine)每 4s 都把大量不变 / 变化很慢的数据重新拉一遍,而且后台标签页照样轮询,于是 RPC 负载随观众人数线性增长。改动(Tier 1,纯前端,无行为变化)
仅改
frontend/src/hooks/useArenaEngine.ts:getAgentgetMatch重拉document.hidden时暂停轮询,切回前台立即补刷效果
MatchSettled/MatchCreated事件订阅保留,新战果仍即时显示。测试
打开
/arena,F12 → Network:① 每秒请求数明显下降;② 切到别的标签 → 请求暂停;③ 切回 → 一波刷新后平稳。tsc --noEmit通过(0 报错)。🤖 Generated with Claude Code