Ensure only one update timeout is scheduled at a time and call gl.flush()
to encourage eager execution
#156
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.
While investigating the way CPU/GPU work is scheduled in Spark I noticed that the GPU work arising from

SparkRenderer.updateInternal
was not immediately executed, but instead waited for the next rAF or flush. See the following screenshot:This PR introduces a
gl.flush()
to encourage eager execution. See WebGL_best_practices#flush_when_expecting_results. The browser can now immediately start the GPU work. Additionally the logic was reworked to:THREE.Matrix4
instance to avoid cloningmatrixWorld
each time (avoids a memory allocation).With these changes the timeline looks as follows:

Edit: for clarity the "GPU idle" and "GPU work" refer to the GPU thread. The key is that no GPU work is scheduled in the before case, whereas it is with this PR. Whether or not the GPU is actually idle at that point obviously depends on other factors. But in case it is, it can immediately start on it.