fix(core): Enable shader/pipeline caching for attached WebGL devices#9971
Conversation
When attaching to an external WebGL context (e.g., MapboxOverlay with interleaved: true), the caching props were not being set, unlike the _createDevice() path which explicitly enables them. This caused severe performance degradation in interleaved mode because luma.gl's PipelineFactory would create new shader pipelines every frame instead of reusing cached ones. The fix adds _cacheShaders: true and _cachePipelines: true to the webgl2Adapter.attach() call, matching the defaults set in _createDevice(). User-provided deviceProps can still override these if needed. Fixes visgl#9839 Related: visgl#9822, luma.gl#2465
chrisgervang
left a comment
There was a problem hiding this comment.
Thank you for submitting this PR - much appreciated! Left one comment. Please confirm there aren't any regressions to the other interleaved renderers - we now have a examples/basemap-browser app to help you quickly QA each integration
| // Enable shader and pipeline caching for attached devices (matches _createDevice defaults) | ||
| // Without this, interleaved mode (e.g., MapboxOverlay) creates new pipelines every frame | ||
| _cacheShaders: true, | ||
| _cachePipelines: true, |
There was a problem hiding this comment.
Let's put this below the spread in case a user wants to customize their device props. By default deviceProps is a {} so the caching will still apply
There was a problem hiding this comment.
Awesome, thank you so much @chrisgervang! That's a great catch: I've gone ahead and made the required change. I've also gone ahead and manually verified the changes via the examples/basemap-browser that you had recommended, and can confirm that no regressions were found, having tested it across all integrations.
Just as a slight note for anyone else wanting to verify the change: I believe that the performance impact scales with scene complexity and interaction frequency. As the examples/basemap-browser are quite simple, the problem doesn't always seem apparent, though this quickly changes in production applications with greater complexity and data.
There was a problem hiding this comment.
Oh my apologies, I misread your code. Your original code allowed the user to customize the props and now it forces the caching. Let's revert to your original version, please.
There was a problem hiding this comment.
Good to hear the example is working!
There was a problem hiding this comment.
Hahaha, no worries! Changes reverted and pushed.
…ys applies. Co-authored-by: chrisgervang <chrisgervang@users.noreply.github.com>
…vices' into fix/enable-caching-for-attached-devices
- Caching is enabled by default - User is able to override default cache-settings via deviceProps should they need.
…vices' into fix/enable-caching-for-attached-devices
…9971) * fix(core): Enable shader/pipeline caching for attached WebGL devices When attaching to an external WebGL context (e.g., MapboxOverlay with interleaved: true), the caching props were not being set, unlike the _createDevice() path which explicitly enables them. This caused severe performance degradation in interleaved mode because luma.gl's PipelineFactory would create new shader pipelines every frame instead of reusing cached ones. The fix adds _cacheShaders: true and _cachePipelines: true to the webgl2Adapter.attach() call, matching the defaults set in _createDevice(). User-provided deviceProps can still override these if needed. Fixes #9839 Related: #9822, luma.gl#2465 * Caching props moved below default deviceProps, to ensure caching always applies. Co-authored-by: chrisgervang <chrisgervang@users.noreply.github.com> * Changes reverted: - Caching is enabled by default - User is able to override default cache-settings via deviceProps should they need. --------- Co-authored-by: Chris Gervang <chrisgervang@users.noreply.github.com>
|
This is great! Thank you! I can confirm this also fixes the bug I raised in #9941 Looking forward to having this published on NPM 🙂 |
This is currently vendored from visgl/deck.gl#9971 because I'm impatient and waiting for 9.2.7 to be pushed to NPM (#220). This closes #106
When attaching to an external WebGL context (e.g., MapboxOverlay with interleaved: true), the caching props were not being set, unlike the _createDevice() path which explicitly enables them.
This caused severe performance degradation in interleaved mode because luma.gl's PipelineFactory would create new shader pipelines every frame instead of reusing cached ones.
The fix adds _cacheShaders: true and _cachePipelines: true to the webgl2Adapter.attach() call, matching the defaults set in _createDevice(). User-provided deviceProps can still override these if needed.
Closes #9839
Related: #9822, luma.gl#2465
Note
Low Risk
Small, localized default-prop change on the external-
gldevice attach path; main risk is unintended behavior change if an integration relied on caching being disabled.Overview
When
Deckis created with an externalglcontext (viawebgl2Adapter.attach), it now explicitly enables shader and pipeline caching by default (_cacheShaders: true,_cachePipelines: true), aligning attached-device behavior with the internal_createDevicepath.This is intended to prevent severe performance regressions in interleaved/external-context integrations (e.g. Mapbox overlays) where pipelines could otherwise be recreated every frame; user
devicePropscan still override these flags via object spread order.Written by Cursor Bugbot for commit 2a6bb54. This will update automatically on new commits. Configure here.