perf(webgl2): skip uniform updates when nothing changed (dirty flag) - #995
Open
Endymi0n74 wants to merge 1 commit into
Open
perf(webgl2): skip uniform updates when nothing changed (dirty flag)#995Endymi0n74 wants to merge 1 commit into
Endymi0n74 wants to merge 1 commit into
Conversation
updateCanvas() was issuing the 7 gl.uniform* calls (plus 7 getUniformLocation in the current TS source) on every refresh, even though all uniform inputs are either options (only mutated via updateOptions) or the canvas drawing-buffer size (fixed at construction). A dirty flag set by updateOptions()/refreshPlayer() turns the steady 60 Hz path into 1 read + 1 branch. Measured on the built bundle (same logic, cached uniform locations): steady-path updateCanvas JS cost drops from ~246 ns/frame to ~12.7 ns/frame (×19.4 vs perf10; up to ×22 with the earlier uniform-cache measurement). Also removes a leftover debug console.log from the hot path.
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.
What
WebGL2Player.updateCanvas()was issuing its 7gl.uniform*calls on every refresh, even though all uniform inputs are constant unless the options change:filterId,qualityMode,sharpenFactor,brightness,contrast,saturation) are only mutated throughupdateOptions(),iResolution←$canvas.width/height) is fixed at construction.A private
_uniformsDirtyflag (set byupdateOptions()andrefreshPlayer()) turns the steady 60 Hz path into 1 field read + 1 branch. Also removes a leftover debugconsole.logfrom the hot path.Why
updateCanvas()runs at the render cadence. In the current TS source it also performs 7gl.getUniformLocation()lookups per call — skipped entirely when nothing changed. The fork that this ports from measured the steady path at ~246 ns/frame → ~12.7 ns/frame (×19.4), with the earlier measurement including the uniform-location cache at ×22.Safety
true, so the initial uniforms are still applied insetupShaders()(which callsupdateCanvas()once at init).updateOptions()(override ofBaseStreamPlayer.updateOptions, same contract:Object.assign+ optionalrefreshPlayer()) andrefreshPlayer()(called by the stream manager on settings changes / player refresh).Measurement
Steady-path
updateCanvas(JS cost only, 60 Hz scenario, Node V8 harness, seeds 42/2024/999 × 3 passes × 200 000 iterations):Visual output unchanged: the same uniform values are written whenever anything changes.