Cut the main-thread cost of opening and re-rendering a visualisation - #2037
Open
NAThompson wants to merge 1 commit into
Open
Cut the main-thread cost of opening and re-rendering a visualisation#2037NAThompson wants to merge 1 commit into
NAThompson wants to merge 1 commit into
Conversation
Profiling the h5wasm demo on a 2068x2162 uint16 frame put most of the time
between clicking a dataset and seeing pixels in avoidable allocation and shader
recompilation. Click-to-figure goes from $211$ ms to $102$ ms.
Per-element allocation: `getBounds` and `getBoundsWithErrors` walked values with
`for..of` and `.entries()`, which allocate per element in V8 and JSC -- scanning
a 34 MB `Float64Array` triggered 4037 young-generation collections where an
indexed loop triggers 4 ($3.25\times$ in V8, $1.25\times$ in SpiderMonkey, which
already elides most of it). The complex visualisations allocated their outputs
with `Array.from({ length: n })`, whose `PACKED_ELEMENTS` kind boxes every value
written in; a `Float64Array` and indexed iteration take $4.19$M values from
$572$ ms to $160$ ms. Both are tested against naive reference implementations,
since hand-written expectations would not pin down code written this way.
Shader recompilation: `HeatmapMaterial` and `GlyphMaterial` rebuilt their `args`
object every render, and R3F compares it element by element, so each re-render
replaced the `ShaderMaterial` and relinked its GLSL -- $1.9$ ms in Chrome,
$4.7$ ms in Firefox. Both now memoize on what actually appears in the shader
source and update the rest in place. `useWarmUpWebGL` moves the first context's
$9$ ms of driver setup into idle time.
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.
Profiling the h5wasm demo on a 2068x2162 uint16 frame put most of the time between clicking a dataset and seeing pixels in avoidable allocation and shader recompilation. Click-to-figure goes from$211$ ms to $102$ ms.
Per-element allocation:$3.25\times$ in V8, $1.25\times$ in SpiderMonkey, which already elides most of it). The complex visualisations allocated their outputs with $572$ ms to $160$ ms. Both are tested against naive reference implementations, since hand-written expectations would not pin down code written this way.
getBoundsandgetBoundsWithErrorswalked values withfor..ofand.entries(), which allocate per element in V8 and JSC -- scanning a 34 MBFloat64Arraytriggered 4037 young-generation collections where an indexed loop triggers 4 (Array.from({ length: n }), whosePACKED_ELEMENTSkind boxes every value written in; aFloat64Arrayand indexed iteration take $4.19$M values fromShader recompilation:$1.9$ ms in Chrome, $4.7$ ms in Firefox. Both now memoize on what actually appears in the shader source and update the rest in place. $9$ ms of driver setup into idle time.
HeatmapMaterialandGlyphMaterialrebuilt theirargsobject every render, and R3F compares it element by element, so each re-render replaced theShaderMaterialand relinked its GLSL --useWarmUpWebGLmoves the first context's