ResourceManager: reference-count consumers of shared in-flight asset loads

Aperta
#3,096 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start with ResourceManager.load(), _loadingPromises, and cancelNotLoaded() to trace how shared AssetPromise instances are created and canceled. Then inspect the GLB sub-asset loading path and existing cancellation tests. Add coverage for first- and later-caller cancellation, shared GLB dependencies, and cleanup after resolve, reject, and cancel; done means one consumer can release without disrupting others, and the shared load cancels only after its final consumer releases it.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Background

ResourceManager deduplicates concurrent asset loads by storing one shared AssetPromise per resolved loading key in _loadingPromises.

This was noticed while reviewing #3084, but the cancellation behavior predates that PR. #3084 only makes virtual, relative, and physical URLs resolve consistently to the same loading key.

Problem

The first caller receives the shared loader promise directly, while subsequent callers receive forwarding promises. This makes cancellation depend on caller order:

const promiseA = resourceManager.load(url);
const promiseB = resourceManager.load(url);

promiseA.cancel();

Because promiseA is also the promise stored in _loadingPromises, canceling it rejects both callers. In contrast, canceling promiseB only cancels its forwarding promise and leaves the shared load running.

cancelNotLoaded(url) also cancels the shared promise for that key, so every pending consumer is rejected. There is currently no consumer ownership or reference count.

The same ownership model matters for GLB sub-assets:

const materialA = resourceManager.load("model.glb?q=materials[0]");
const materialB = resourceManager.load("model.glb?q=materials[1]");

Both sub-assets depend on the same main GLB load. Releasing one consumer should not cancel the main load while another consumer still depends on it.

Proposed direction

Store a loading entry instead of only a promise:

interface LoadingEntry<T> {
  promise: AssetPromise<T>;
  refCount: number;
}
  • Keep the shared loader promise internal.
  • Return an independent consumer promise/handle from every load() call, including the first.
  • Increment the reference count when a consumer joins an in-flight load.
  • Decrement it exactly once when that consumer cancels.
  • Cancel the shared load only when the last consumer releases it.
  • Track sub-asset dependencies so a main GLB load remains alive while any requested sub-asset still needs it.
  • Define cancelNotLoaded(url) explicitly as either a force-cancel API or a single-reference release; keeping it as force-cancel would preserve its current resource-manager-level semantics.

Acceptance criteria

  • Canceling either of two callers loading the same URL does not reject the other caller.
  • The underlying shared promise is canceled only after the last active consumer cancels.
  • Canceling one GLB sub-asset consumer does not affect another sub-asset consumer.
  • Entries and reference counts are cleaned up after resolve, reject, and cancel.
  • Tests cover cancellation initiated by both the first and later callers.
Lingua principale
TypeScript
Stelle
5.9k
Fork
413
Merge medio
16h 17m
PR unite (30g)
41

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di galacean/engine

Tutte le issue di galacean/engine

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.