Skip to content

fix(textures): retry with backoff, on-screen uploads first, fetch timeout, LRU eviction - #1

Closed
avijit213 wants to merge 2 commits into
solid-tv:mainfrom
avijit213:feat/appletv-texture-loading
Closed

avijit213 wants to merge 2 commits into
solid-tv:mainfrom
avijit213:feat/appletv-texture-loading

Conversation

@avijit213

@avijit213 avijit213 commented Nov 6, 2026 •

Copy link
Copy Markdown

Why

On a NativeScript tvOS app (Apple TV, @nativescript/canvas WebGL, no image workers), poster cards sometimes stayed empty for the rest of the session. They were worst after navigating back to a page and while a video played under the canvas. Four renderer behaviours combined to cause it:

  1. Retries never used the app's setting. CoreNode's src setter creates the ImageTexture without maxRetryCount, so resolveDefaults filled in a hard 5. The stage's maxRetryCount never reached an image. The retries also ran back to back, so a few seconds of bad network used them all up, and the node was never drawn again.
  2. Preload-margin images competed with on-screen ones. The upload queue is first-in, first-out, so posters in the bounds margin went ahead of the posters on screen.
  3. A request could hang forever. On tvOS the NativeScript XHR sometimes never reports completion, even though the server has answered. WebPlatform.fetch has no deadline, so that image never loaded and never failed, which means it never retried either.
  4. Cleanup freed the wrong textures. Memory cleanup frees the oldest loaded textures first. That evicted a home page's posters, which loaded first but are one Back press away, before a detail page's posters, which won't be seen again.

What changes

Area Change Files
Retries ImageTexture keeps the stage's maxRetryCount unless one is passed explicitly (maxRetryCount?: number | null, default null). After a failure the next load() waits, doubling from 1s to 60s (Texture.retryAt, with a timer that reloads only if a node still owns the texture). textures/ImageTexture.ts, textures/Texture.ts
On-screen first When a node enters InViewport, its texture moves to the front of the upload queue (CoreTextureManager.prioritize). A texture whose node came on screen while it was still fetching is queued at the front. A frame counter (CoreTextureManager.frame, advanced in Stage.drawFrame) dates this. CoreNode.ts, CoreTextureManager.ts, Stage.ts
Fetch timeout WebPlatform.fetch rejects after 5s and aborts the XHR, so the texture fails and goes through the retry path. A healthy poster request finishes well under a second. platforms/web/WebPlatform.ts
Eviction TextureMemoryManager.cleanup frees textures least recently on screen first (Texture.lastOnScreen). Textures still owned by a node count as on screen now. TextureMemoryManager.ts, textures/Texture.ts
Tests The CoreNode test stage mock gets a txManager, which updateRenderState now calls. CoreNode.test.ts

Behaviour for apps that set nothing: images now retry maxRetryCount times (default 5, as before), with a growing wait instead of immediately. Nothing else changes until a texture fails, a node enters the viewport or memory cleanup runs.

Testing

  • tsc --build passes. vitest run: 8 files, 115 tests pass. ESLint shows no errors; the no-explicit-any warnings were there before this change.
  • The same changes run in the Hoichoi Apple TV app as a pnpm patch on @solidtv/renderer 1.10.2. On the tvOS simulator, a test server returned 503 for one poster for 40s and then served it. The renderer made one request at a time at 4, 6, 8, 12, 20 and 36s, and the poster appeared at 68s, in 2 runs out of 2. Back to a page after scrolling another showed every poster with no refetch, and the log showed no console errors.

Notes

  • This is a port: the app runs @solidtv/renderer 1.10.2, whose source isn't in this repo, and this branch is the @lightningjs/renderer 3.0.5 tree. The 1.10.2 patch also gives uploads a 4ms budget while animations run, instead of one texture per frame. This tree already uses the time budget, so that part has no counterpart here.
  • The patch is recorded in Hoichoi.SharedClientPlatform: apps/appletv/patches/@solidtv__renderer@1.10.2.patch, with notes in apps/appletv/patches/README.md.

…eout, LRU eviction

- Image textures use the stage's maxRetryCount instead of a hard 5 the
  src setter never overrode, and wait between retries (1s doubling to
  60s) instead of spending them all back to back.
- A texture whose node enters the viewport uploads ahead of textures
  preloading in the bounds margin.
- WebPlatform.fetch fails after 15s, so a request that never completes
  (seen on tvOS NativeScript) is retried instead of hanging forever.
- Memory cleanup frees the least recently shown textures first instead
  of the oldest loaded.

Ported from the Hoichoi Apple TV patch on @solidtv/renderer 1.10.2.
@avijit213 avijit213 changed the title fix(textures): retry with backoff, on-screen uploads first, fetch tim… fix(textures): retry with backoff, on-screen uploads first, fetch timeout, LRU eviction Nov 6, 2026
A healthy poster request finishes well under a second; at 15s a stalled
request held the image back far longer than the retry needs to recover
it.
@avijit213

Copy link
Copy Markdown
Author

Hi @chiefcll could you please review once ? thank you!

@chiefcll

Copy link
Copy Markdown

👋 - I'll take a look and see if this is needed on the other renderer, this isn't the SolidTV renderer, it's the one used on LightningJS

@chiefcll

Copy link
Copy Markdown

FYI - closing out. The nativescript 2.0 should be using renderer 2.0 and everything in here is in that...

@chiefcll chiefcll closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants