Skip to content

Commit f026762

Browse files
jushgithub-actions[bot]
authored andcommitted
Avoid creating anonymous objects when rendering view annotations (#6263)
While doing some measurements I noticed that when we are showing view annotations we create objects on every frame: <img width="3008" height="1667" alt="Screenshot 2025-09-03 at 16 16 04" src="https://github.com/user-attachments/assets/27200dc0-4235-4b60-807f-412d5e21dee8" /> This PR avoids creating those objects due to the swapBuffers call. cc @mapbox/maps-android GitOrigin-RevId: 15e2c7286e9ac02781f01a679742c11cd0164474
1 parent 0a5d7df commit f026762

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

maps-sdk/src/main/java/com/mapbox/maps/renderer/MapboxRenderThread.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ internal class MapboxRenderThread : Choreographer.FrameCallback {
370370
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0)
371371
}
372372

373+
/**
374+
* Keep a [Choreographer.FrameCallback] to [swapBuffers] to avoid creating a new one on every time.
375+
*/
376+
private val swapBuffersFunc = Choreographer.FrameCallback { swapBuffers() }
377+
373378
@OptIn(MapboxExperimental::class)
374379
private fun draw(frameTimeNanos: Long) {
375380
if (!fpsManager.preRender(frameTimeNanos, renderThreadStatsRecorder?.isRecording == true)) {
@@ -407,9 +412,7 @@ internal class MapboxRenderThread : Choreographer.FrameCallback {
407412
// when we're syncing view annotations with the map -
408413
// we swap buffers the next frame to achieve better synchronization with view annotations update
409414
// that always happens 1 frame later
410-
Choreographer.getInstance().postFrameCallback {
411-
swapBuffers()
412-
}
415+
Choreographer.getInstance().postFrameCallback(swapBuffersFunc)
413416
// explicit flush as we will not be doing any drawing until buffer swap for the next frame -
414417
// we send commands to GPU this frame as we should have some free time and perform buffer swap asap on the next frame
415418
// note that this doesn't block the calling thread, it merely signals the driver that we might not be sending any additional commands.

0 commit comments

Comments
 (0)