Skip to content

Conversation

@goyalpalak18
Copy link
Contributor

Description

I identified a GPU memory leak in the loadGLTFGeometryInternal function within import-manager.ts.

When loading detector geometries, we clone the individual meshes to merge them into a single buffer. However, I noticed that we weren't disposing of those intermediate clones. In three.js, .clone() allocates new GPU buffers that persist until they are manually disposed, even if the JavaScript objects are garbage collected.

This was causing significant video memory accumulation—around 50-150MB per ATLAS load—which eventually led to browser crashes or black screens if a user switched between experiments multiple times in one session.


Fix

I updated the loading logic to manually dispose of all the intermediate cloned geometries immediately after they are merged into the final mesh.

This ensures that we only keep the final result in GPU memory and properly free up the temporary buffers. This change also brings import-manager.ts in line with the disposal patterns we already use in other parts of the codebase, like phoenix-objects.ts.


Impact

  • Stability: This eliminates the Out of Memory crashes and WebGL context loss we've seen during multi-experiment demos.
  • Performance: It prevents the frame rate from degrading over time due to memory saturation.
  • Risk: Very low. This is strictly a memory management cleanup and doesn't change the visual output or the logic of the merged mesh.

Test Plan

  1. Open Chrome DevTools and navigate to the Performance Monitor.
  2. Watch the JS Heap and GPU Memory usage.
  3. Load the ATLAS detector geometry.
  4. Clear the geometry or switch to a different experiment (like LHCb).
  5. Reload ATLAS.
  6. Verify: You should see the memory usage spike during the load but return to baseline after the merge completes, rather than stepping up and staying high.

Signed-off-by: goyalpalak18 <goyalpalak1806@gmail.com>
@goyalpalak18
Copy link
Contributor Author

Hey @EdwardMoyse! I fixed the memory leak by cleaning up those intermediate geometries. Ready for a review when you have a moment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant