BabylonJS / BabylonJS/BabylonNative

GLTF Loader non-cached HTTP requests

Open
#538 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
919
Forks
162
Avg merge
1d 15h
Merged PRs (30d)
19

Description

# Context
While debugging the Linux Dead lock, I logged all the xmlHTTPRequest and found the same requests for some .gltf. Textures are loaded multiple times (requests with related allocations). Loaded but not uploaded to VRAM as there is a cache mecanism but too late in the loading pipeline.

# Pipeline
Textures found in the .gltf are loaded async in a buffer:
https://github.com/BabylonJS/Babylon.js/blob/af28ff68fcf6f782f8dec7f0494d5fced8a2948f/loaders/src/glTF/2.0/glTFLoader.ts#L2020
and
https://github.com/BabylonJS/Babylon.js/blob/af28ff68fcf6f782f8dec7f0494d5fced8a2948f/loaders/src/glTF/2.0/glTFLoader.ts#L2096

Then, this buffer is sent to the engine to create a texture with. But a texture cache discards that buffer if the URL is already present:
https://github.com/BabylonJS/Babylon.js/blob/b8238023e50655c58361136a88fcd7e88f06772d/src/Materials/Textures/texture.ts#L371

So, some buffers are discarded but the request and loading is done in NativeEngine. I guess there is a cache mecanism in the browser to overcome this kind of issue. Maybe also the OS. But memory allocation and latency is a performance issue. Let alone bandwidth quota on mobile.

# Fix proposal
- Add a cache memory in xmlHTTPRequest with a configurable memory size
- Add a cache in GLTFLoader to not load multiple times the same URL (I prefer this option as babylonjs will benefit as well)

ping @ryantrem

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.