Memory leak in Babylon React Native app - Engine._renderLoop()


Our Babylon React Native Android app’s performance slowly degrades over time until the app crashes. Initial investigations suggest a memory leak from Engine._renderLoop() as the performance degradation occurs despite no new geometry or shaders being added to the scene. The user can simply be occasionally rotating, panning and zooming the ArcRotateCamera around the scene and the frame rate falls.

Unsure if it’s an issue with our code or that of Babylon.js or Babylon Native. I’ve yet to replicate this in a simpler app.

Does anyone on the Babylon Native team have any advice on how we can better investigate this to narrow down the issue?

I guess you need a profiler. If you are using React Native with JSC, I don’t believe it is possible to profile JSC on Android, but it should be possible on iOS. If you are targeting Hermes, then it should be possible on Android or iOS but I’ve never tried it myself. Otherwise, adding code to time the render loop and slowly change the code to drill into the slow parts is likely your best bet. Does the same slowness happen with the Playground app for Babylon React Native?

We’ve done some profiling with Flipper on Android, which is what helped us to identify _renderLoop() but I guess we need to do more investigation.

We’re using V8 on Android. We do also test on iOS but we’ve yet to confirm if the issue is evident on that platform also.

I’ll try to replicate the issue in the Playground App and get back to you as soon as I can.

I just wanted to reach out now in case there was any known issue you were aware of.

Do you repro with BabylonNative alone? if it happens in Engine._renderLoop() then it should also be visible in BN alone. It makes debugging easier. Moreover, with ChromeDevTools and V8, you should be able to do memory snapshots.

Thanks @Cedric. I’ll give it a try.

1 Like

@Cedric @bghgary most of the memory use seems to be in bindBuffers and I found this open issue Improve Vertex Buffer Binding · Issue #361 · BabylonJS/BabylonNative · GitHub

Could it be related?

I’m still investigating and trying to replicate in a small use case.

Hard to say. Do you create/recreate vertex buffers in your app? Like updating meshes

What I’m seeing at the moment is the issue seems to be isolated to V8 JIT (version 10.100.1). When I switch to either JavaScriptCore or Hermes I see no evidence of a memory leak, plus the debugging and profiling options for Hermes are a lot better. V8 JIT is better for intensive data processing though, which is one of our requirements. I’ll try updating the V8 version …

1 Like