r/learnprogramming • • 12d ago

Trying to understand how to properly optimize larger React Three Fiber scenes

I've been working on a project with React Three Fiber and Three.js where I have multiple 3D houses made in Blender and exported as GLB files. Each house has quite a few objects, different materials, furniture and stuff like that. I'm trying to understand how people usually handle performance when a scene starts getting more complicated, especially on mobile.

I've been reading about reducing draw calls, reusing materials, limiting DPR and using frameloop="demand". But I'm still not entirely sure what makes the biggest difference in practice. For example, if you have several GLB models that users can switch between, is it generally better to keep them loaded in memory or dispose of everything when switching scenes?

I'm also curious how you figure out whether the main bottleneck is React, Three.js or just the models themselves. I know profiling is important, but I'm still learning which metrics to pay attention to.

Would appreciate some advice from people who've worked with larger R3F projects. Mostly trying to understand how to approach optimization properly instead of randomly changing settings and hoping the FPS improves.

3 Upvotes

7 comments sorted by

2

u/ymgymg 12d ago

I'd profile before touching settings. Drop r3f-perf in and watch draw calls and triangles. If calls are in the hundreds it's the models (merge meshes, share materials, run them through gltf-transform), and if they're low but FPS still drops it's usually React re-rendering something every frame. For switching houses I'd keep them cached with useGLTF.preload unless mobile memory starts hurting.

1

u/swilson_769 6d ago

Low draw calls don't prove React is the bottleneck; shaders, shadows, or pixel cost can dominate. A lower-DPR test can help separate GPU cost from CPU work.

1

u/lisa_j_870 6d ago

Make one change at a time and compare the same scene on the target phone, recording frame time and memory as well as FPS. Counts are clues; the before/after tells you what helped.

1

u/Stunning_Blood_8587 6d ago

check the texture dimensions before deciding how many houses to keep loaded. one uncompressed 4k rgba texture is about 85 MiB on the gpu with mipmaps, even if the jpg inside the glb is tiny. try the same house with 2k maps on your target phone before changing how you cache the models.