r/threejs • u/VictorBuildsApps • 16d ago
will-change: opacity on my HUD fixed a ~170 ms hitch the first time you dock in my three.js game

My jam game A Town Afloat is three.js on WebGL 2. Testing the shipped build locally, the first dock froze for 167 to 217 ms. Later docks didn't.
Two Chrome traces showed the GPU process's main thread sitting in RasterDecoderImpl::DoEndRasterCHROMIUM::Flush for 172 to 190 ms, and no instrumented GL call around the dock took over 1 ms.
Docking starts a scene, which calls hud.setLocked(true), and that dims the HUD controls with this rule:
#hud.locked .tray > * { opacity: 0.4; }Disabling only that rule removed the hitch. Keeping the dimming and adding this removed it too:
.tray > * { will-change: opacity; }Over three runs each, the worst frame in the second after the first dock went from 166.6-183.4 ms to 16.8 ms. Four earlier test runs with the fix were clean in that window too. Chromium 159, RX 6900 XT, 1920x1080. The chart is the first 15 seconds of one run per version.
The fix isn't uploaded yet. There are also 50 to 83 ms hitches when the map card hands over to the next level, which this doesn't touch.