I have a ~5 MB GLTF file that is consuming about 9 GB of memory during and after loading. The file has no textures, just meshes. This 1800x increase in size seems a bit excessive, and Iβm wondering if this is due to something goofy about the GLTF file itself, or if it could be a bug in the GLTF loader, or if this is just the way it has to be because of WebGL reasons.
oval.gltf (4.6 MB)
@gltf-transform inspect
(see below) says that the file has just a single mesh of size 1.23 MB, with 9928 primitives and 386,437,472 vertices. Iβm assuming that the majority of those vertices are reused in order for the mesh to only require 1.23 MB.
But it looks like the GLTF loader is creating about 9 GB of array buffers:
Inspecting the resulting scene shows a group of 9928 meshes, as expected:
And here is one of the geometries of those meshes:
Whatβs notable is that every single one of the meshes has identical position
and normal
arrays. This makes sense, as those arrays should just mirror the buffer in the gltf file. (This being a BufferedGeometry, each mesh should just consume the array indexes that it is interested in.) And so I would expect each geometry to point to the same FloatArray32 reference. At first glance, this appears to be the case:
However, for some reason, starting with index 317 a new array is allocated for each mesh:
And this continues all the way to the last mesh. This is very suspicious, and looks like a bug, but I canβt be sure without understanding how GLTFLoader.js works a lot better than I do now. I wanted to post this question here first to see if there may be something obvious that Iβm just not aware of as to why the loader is using so much memory and copying the arrays instead of reusing them.
Hereβs the output from @gltf-transform inspect
:
OVERVIEW
ββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β key β value β
ββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β version β 2.0 β
ββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β generator β β
ββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β extensionsUsed β KHR_texture_transform, KHR_materials_specular, KHR_materials_transmission β
ββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β extensionsRequired β none β
ββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SCENES
ββββββββββββββββββββββββββββββββββββββββββββ
βββββ¬βββββββ¬βββββββββββ¬ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββ
β # β name β rootName β bboxMin β bboxMax β
βββββΌβββββββΌβββββββββββΌββββββββββββββββββββββββββββΌβββββββββββββββββββββββββ€
β 0 β β β -0.0762, -3.9624, -0.0508 β 0.0762, 3.9624, 0.0508 β
βββββ΄βββββββ΄βββββββββββ΄ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββ
MESHES
ββββββββββββββββββββββββββββββββββββββββββββ
βββββ¬βββββββ¬ββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββ¬βββββββββββββββ¬ββββββββββββββ¬ββββββββββ¬βββββββββββββββββββββββββββ¬ββββββββββββ¬ββββββββββ
β # β name β mode β primitives β glPrimitives β vertices β indices β attributes β instances β sizeΒΉ β
βββββΌβββββββΌββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββΌβββββββββββββββΌββββββββββββββΌββββββββββΌβββββββββββββββββββββββββββΌββββββββββββΌββββββββββ€
β 0 β β TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN β 9,928 β 374,084,682 β 386,437,472 β u32 β NORMAL:f32, POSITION:f32 β 1 β 1.23 MB β
βββββ΄βββββββ΄ββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββ΄βββββββββββββββ΄ββββββββββββββ΄ββββββββββ΄βββββββββββββββββββββββββββ΄ββββββββββββ΄ββββββββββ
ΒΉ size estimates GPU memory required by a mesh, in isolation. If accessors are
shared by other mesh primitives, but the meshes themselves are not reused, then
the sum of all mesh sizes will overestimate the asset's total size. See "dedup".
MATERIALS
ββββββββββββββββββββββββββββββββββββββββββββ
βββββ¬βββββββ¬ββββββββββββ¬βββββββββββ¬ββββββββββββ¬ββββββββββββββ
β # β name β instances β textures β alphaMode β doubleSided β
βββββΌβββββββΌββββββββββββΌβββββββββββΌββββββββββββΌββββββββββββββ€
β 0 β β 9,928 β β OPAQUE β β β
βββββ΄βββββββ΄ββββββββββββ΄βββββββββββ΄ββββββββββββ΄ββββββββββββββ
TEXTURES
ββββββββββββββββββββββββββββββββββββββββββββ
No textures found.
ANIMATIONS
ββββββββββββββββββββββββββββββββββββββββββββ
No animations found.