Code Monkey home page Code Monkey logo

Comments (6)

donmccurdy avatar donmccurdy commented on September 28, 2024 3

@xingxiang1227 high resolution images consume an enormous amount of memory. With TextureLoader, the compressed image is held in CPU memory, and the first time it's rendered, the WebGL API is blocked while decompressing and uploading it to the GPU. For a 4K texture that's 90 MB of memory.

The reason we use ImageBitmapLoader is that it moves the decompression off the main thread, allowing us to block rendering for a shorter amount of time. The memory cost on the GPU is the same. I'm unsure of the difference in CPU memory, or whether Chrome's Task Manager is able to measure both accurately.

Additionally, the Web Workers used to decode Draco-compressed data will need some unknown amount of CPU memory.

You can opt out of both in your own application – for example, using TextureLoader or (better yet) KTX2 compressed textures. See my blog post, Choosing Texture Formats for WebGL and WebGPU, for more on that. Or you can skip using Draco compression in favor of lighter-weight Meshopt compression or quantization.

These all have tradeoffs, among which CPU memory is just one, so I'm not sure there's much we can change about the Editor here. If you're having particular problems managing memory in your own application, please feel welcome to start a thread in https://discourse.threejs.org/ and we can probably help you optimize memory there.

from three.js.

mrdoob avatar mrdoob commented on September 28, 2024 1

The editor may be saving the textures as jpeg into indexedDB. Is that what you're trying to report?
And... Is 290,068 kb really high memory usage for you?

from three.js.

donmccurdy avatar donmccurdy commented on September 28, 2024 1

Might be related to the Web Workers spawned and WASM allocated while decoding Draco compression. I'm not sure if the editor keeps those workers around for reuse, or disposes them eventually. For this particular model, the geometry is not that heavy – Meshopt compression might be more appropriate.

This model also contains two 4K textures, with estimated GPU memory cost of 90 MB each. My confidence is low that Chrome's tab manager reports GPU memory accurately, but the numbers here do seem within reason.

from three.js.

xingxiang1227 avatar xingxiang1227 commented on September 28, 2024

The editor may be saving the textures as jpeg into indexedDB. Is that what you're trying to report? And... Is 290,068 kb really high memory usage for you?

Hello, in my actual project, a 150MB model, when loaded through GLTFLoader, ultimately occupies 3GB of memory, whereas when stored through indexedDB and rendered again, it only occupies around 700MB. Is there room for optimization in memory management when using GLTFLoader for loading?

from three.js.

xingxiang1227 avatar xingxiang1227 commented on September 28, 2024

Might be related to the Web Workers spawned and WASM allocated while decoding Draco compression. I'm not sure if the editor keeps those workers around for reuse, or disposes them eventually. For this particular model, the geometry is not that heavy – Meshopt compression might be more appropriate.

This model also contains two 4K textures, with estimated GPU memory cost of 90 MB each. My confidence is low that Chrome's tab manager reports GPU memory accurately, but the numbers here do seem within reason.

After my testing, for models with many textures, the memory usage when using GLTFLoader for loading is much higher than that after conversion through indexedDB. Is there room for optimization in memory management when using GLTFLoader?

from three.js.

xingxiang1227 avatar xingxiang1227 commented on September 28, 2024

In the GLTFLoader.js file, within the GLTFParser class, the textures are loaded using this.textureLoader = new ImageBitmapLoader( this.options.manager ), which results in a high memory footprint. After I replaced it with this.textureLoader = new TextureLoader( this.options.manager ), the memory usage became normal. The memory consumption of the former is about 6 times that of the latter. Is there a way to optimize the memory usage of ImageBitmapLoader?
GLTFLoader-GLTFParser

from three.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.