fix(client): fallback to full border recompute on massive tile changes#4576
Conversation
Walkthrough
ChangesBorder compute safeguards
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/client/render/gl/passes/BorderComputePass.ts (1)
200-200: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider extracting the
2048threshold into a named constant.A named constant such as
SCATTER_FULL_RECOMPUTE_THRESHOLDwould make the intent self-documenting and simplify future tuning.♻️ Optional refactor
+private static readonly SCATTER_FULL_RECOMPUTE_THRESHOLD = 2048; + patchTile(x: number, y: number, prevOwner: number, newOwner: number): void { if (this.globalDirty) return; - if (this.scatter.count > 2048) { + if (this.scatter.count > BorderComputePass.SCATTER_FULL_RECOMPUTE_THRESHOLD) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/client/render/gl/passes/BorderComputePass.ts` at line 200, Extract the literal 2048 used in the condition within BorderComputePass into a named constant such as SCATTER_FULL_RECOMPUTE_THRESHOLD, then use that constant in place of the literal while preserving the existing comparison behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/client/render/gl/passes/BorderComputePass.ts`:
- Line 200: Extract the literal 2048 used in the condition within
BorderComputePass into a named constant such as
SCATTER_FULL_RECOMPUTE_THRESHOLD, then use that constant in place of the literal
while preserving the existing comparison behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1858e443-5805-4391-938c-0857d989cb18
📒 Files selected for processing (1)
src/client/render/gl/passes/BorderComputePass.ts
Add approved & assigned issue number here:
Resolves #3604
(related)
Description:
Fixes severe client-side lag spikes (framerate dropping to single digits) when multiple nuclear bombs detonate close to each other with
"isWaterNukes": trueenabled.Water nukes convert land to water on detonation. For an Atom Bomb (radius 30), this changes up to 2,800 tiles.
The client splits these changes across 16 frames (
dripBuckets), processing ~150 tile changes per frame.For each tile change,
BorderComputePass.patchTilecomputes updates. If the victim's territory is highlighted, the pass expands the repaint area of each tile change to ahighlightThickenChebyshev box of radius 4 (meaning9x9 = 81points).This forces the CPU to calculate and push up to
150 * 81 = 12,150points per frame to the border scatter buffer, uploading it, and rendering it as thousands of overlapping GPUPOINTSusing the complex border shader.Under consecutive detonations, this completely freezes the client rendering thread, leading to disconnections.
Optimizes
BorderComputePass.tsto fallback to a full-screen quad border recompute if the scatter point count exceeds a threshold of2,048points.Bypasses the expensive CPU coordinate expansions and array resizing for subsequent tile updates in the same frame.
The GPU renders a simple fullscreen quad to rebuild all borders, which is extremely parallelized and executes in
<0.1ms, keeping gameplay smooth.Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
blontd6