perf(ShaderView): share one GPUDevice across all ShaderViews - #24
Merged
Conversation
Each ShaderView used to request its own adapter + device. A screen that mounts several effects (e.g. Banners, card stacks) therefore spun up N devices on the one background runtime — real GPU/memory cost and slower init. Introduce a module-level shared GPUDevice singleton (getSharedGPUDevice) that every view awaits. The promise is cached for the JS runtime's lifetime and self-heals: if the device is lost, the cache is cleared so the next mount requests a fresh one. Because the device is now shared, useWGPUSetup no longer destroys it on unmount. Per-view resources (uniform buffer) are still torn down by the render loop; pipeline/shader modules are released when the loop's worklet closure is GC'd. Verified on iOS: Banners screen renders all 5 effects off one device, and unmount → remount reuses the still-alive device.
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
Each
ShaderViewpreviously requested its ownadapter+device. A screen that mounts several effects (Banners, card stacks, the home list's live thumbnails) therefore spun up N GPUDevices on the one background runtime — real GPU/memory cost and slower init.This introduces a module-level shared
GPUDevicesingleton (getSharedGPUDevice) that every view awaits. The promise is cached for the JS runtime's lifetime and self-heals: if the device is lost, the cache is cleared so the next mount requests a fresh one.Lifecycle change
Because the device is now shared,
useWGPUSetupno longer destroys it on unmount. Per-view resources (the uniform buffer) are still torn down by the render loop; pipeline/shader modules are released when the loop's worklet closure is GC'd.Verification (argent, iOS — iPhone 17)
Files
src/utils/gpuDevice.ts(new) — the singletonsrc/hooks/useWGPUSetup.tsx— use the shared device; drop per-view device destroy