You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Frequent GeoJSONSource updates force GC every couple seconds #14048
With looking into global reference overflow issue from #14010, I have been profiling different components in the SDK and noticing that using LocationComponent results in gc'ing every couple seconds with the SimpleLocationActivity while not interacting:
LocationComponentCompassEngine#updateRotation seems to be source.
Tracking down which part concretely.
update: when we receive a sensor change event, we are recreating all animators with updateCompassAnimators and calling playAnimators inside of feedNewCompassBearing this is the source of the gc thrashing.
update2: was able to pinpoint that the setGeoJson is the large part of the memory thrashing and not the recreating/playing of the animators.
I've noticed, that all other objects ignored/commented out, it's the constant detaching and attaching of the JVM env to different threads that invokes GC runs. Here's a PR that tries to minimize that for the GeoJSONSource's async features conversion - #14375. I can see a great decrease in the GC runs, however, a lot of them are still coming from other places, like the MapRenderer.
Because when animating (for example LocationComponent or the AnimatedSymbolLayerActivity) we are generating new tiles and rendering really quickly, and because the MapRenderer uses a shared thread pool, the renderer is the main source of the attach/detach calls. Should we make a fixed thread pool of non-rotating threads for the renderer as well?
All above is based on my experimental discovery that attaching and detaching threads is the root cause, I'm not sure if there's anything deeper in our JNI wrapper that might help decrease GC runs instead.
changed the title [-]Simple Location Activity gc'ing every couple seconds[/-][+]Frequent GeoJSONSource updates force GC every couple seconds[/+]on Apr 9, 2019
Attaching a thread to the JVM indeed forces a sync with the GC (which may or may not require the GC to run).
Following that lead, I noticed that shared thread pool's threads are not manually attached to the JVM (in contrast to the run loop's implementation). This means that they always fall into JNI_EDETACHED branch:
while calling android::AttachEnv() and are detached as soon as the variable goes out of the scope because of the true flag passed to the JNIEnvDeleter.
To get rid of the unnecessary GC runs we need to introduce an Android's shared thread pool implementation that manually attaches/detaches the threads to JVM when they are created/destroyed and rely on android::AttachEnv() only for getting the env reference.
Activity
tobrun commentedon Mar 6, 2019
Setting
locationComponent.setRenderMode(RenderMode.NORMAL)doesn't show the GC'ing:We need to optimize
RenderMode.COMPASStobrun commentedon Mar 6, 2019
LocationComponentCompassEngine#updateRotationseems to be source.Tracking down which part concretely.
update: when we receive a sensor change event, we are recreating all animators with updateCompassAnimators and calling playAnimators inside of
feedNewCompassBearingthis is the source of the gc thrashing.update2: was able to pinpoint that the setGeoJson is the large part of the memory thrashing and not the recreating/playing of the animators.
tobrun commentedon Mar 14, 2019
With using:
I'm getting better results:
This can be used as intermediate solution until we tackled the root cause of this issue.
LukasPaczos commentedon Apr 9, 2019
I've noticed, that all other objects ignored/commented out, it's the constant detaching and attaching of the JVM env to different threads that invokes GC runs. Here's a PR that tries to minimize that for the
GeoJSONSource's async features conversion - #14375. I can see a great decrease in the GC runs, however, a lot of them are still coming from other places, like theMapRenderer.Because when animating (for example
LocationComponentor theAnimatedSymbolLayerActivity) we are generating new tiles and rendering really quickly, and because theMapRendereruses a shared thread pool, the renderer is the main source of the attach/detach calls. Should we make a fixed thread pool of non-rotating threads for the renderer as well?All above is based on my experimental discovery that attaching and detaching threads is the root cause, I'm not sure if there's anything deeper in our JNI wrapper that might help decrease GC runs instead.
/cc @ivovandongen
[-]Simple Location Activity gc'ing every couple seconds[/-][+]Frequent GeoJSONSource updates force GC every couple seconds[/+]LukasPaczos commentedon Apr 12, 2019
Capturing from @ivovandongen in #14375:
Following that lead, I noticed that shared thread pool's threads are not manually attached to the JVM (in contrast to the run loop's implementation). This means that they always fall into
JNI_EDETACHEDbranch:mapbox-gl-native/platform/android/src/attach_env.cpp
Lines 14 to 15 in f3341dd
while calling
android::AttachEnv()and are detached as soon as the variable goes out of the scope because of thetrueflag passed to theJNIEnvDeleter.To get rid of the unnecessary GC runs we need to introduce an Android's shared thread pool implementation that manually attaches/detaches the threads to JVM when they are created/destroyed and rely on
android::AttachEnv()only for getting theenvreference.