-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix annotation update missing issue. #441
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Chaoba I don't think it's a good idea although I understand how this solves a problem.
Root cause of underlying issue is posting updates very frequently. It basically does not make any sense as we can't render let's say 100 times each 1 ms - we depend on vsync updates and render each 16 ms (on most screens).
If we remove the code here like you did - we will have issues in parsing large geojson files. E.g. user has set to parse enormous geojson_1 and while parsing is happening also queued 100 more. There is no sense to parse 99 of them because they will be basically overwritten by the most recent one and if we do not overwrite - it will result in huge delay of showing this geojson data on map.
My proposal here for you case would be introducing handler inside annotation plugin and queue updates there.
The root cause for this issue is that there are too many updates and the most recent update cancels the former update. Simply introducing a handler in the annotation plugin will not resolve this issue, because all the updates in this handler will return immediately as the parse works are handled in the handler of GeojsonSource. |
@Chaoba again, I fully understand your fix. All what I'm saying is that changing that logic in geojson in not correct. Yes, it will fix annotations but this approach is not correct as we apply map updates asap and not queue them up. Line 365 in d95bef4
Why can't we add that logic here? Not updating next feature until previous one is parsed. |
deb2ba2
to
89b2b07
Compare
plugin-annotation/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationManagerImpl.kt
Outdated
Show resolved
Hide resolved
plugin-annotation/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationManagerImpl.kt
Outdated
Show resolved
Hide resolved
plugin-annotation/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationManagerImpl.kt
Outdated
Show resolved
Hide resolved
@@ -118,7 +141,7 @@ class PointAnnotationActivity : AppCompatActivity() { | |||
} | |||
// random add symbols across the globe | |||
val pointAnnotationOptionsList: MutableList<PointAnnotationOptions> = ArrayList() | |||
for (i in 0..20) { | |||
for (i in 0..2000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it intended to leave this large number here? or were you just testing? 😄
perhaps better having an integration test appying 2000 updates and verifying that all calls where executed (and not were skipped).
plugin-annotation/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationManagerImpl.kt
Outdated
Show resolved
Hide resolved
sdk-base/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationPlugin.kt
Outdated
Show resolved
Hide resolved
plugin-annotation/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationPluginImpl.kt
Outdated
Show resolved
Hide resolved
plugin-annotation/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationManagerImpl.kt
Outdated
Show resolved
Hide resolved
ac66525
to
db73c06
Compare
94fccf2
to
6f8996b
Compare
private val workerHandler by lazy { | ||
Handler(workerThread.looper) | ||
} | ||
private val mainHandler = Handler(Looper.getMainLooper()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw I guess it could be static, no need to create each time, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this one could be static.
private val workerHandler by lazy { | ||
Handler(workerThread.looper) | ||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) | ||
var workerThread = HandlerThread("STYLE_WORKER").apply { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we revert lazy initialization? That thread in some situations may not even be started (if user does not use geojson source). I'm OK to leave it internal for tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a compromise for tests. With lazy initialization, only the first case will succeed, in the following one, this thread will be in the inactive state.
a7d0e0e
to
36a4dd0
Compare
...androidTest/java/com/mapbox/maps/testapp/annotation/UpdateAnnotationWithMultiManagersTest.kt
Outdated
Show resolved
Hide resolved
...androidTest/java/com/mapbox/maps/testapp/annotation/UpdateAnnotationWithMultiManagersTest.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with couple small questions.
36a4dd0
to
b2cfd67
Compare
PRs must be submitted under the terms of our Contributor License Agreement CLA.
Fixes: #433
Pull request checklist:
mapbox-maps-android
changelog:<changelog>Fix annotation update missing issue</changelog>
.Summary of changes
Some annotation updates could be ignored as we will remove the pending GeojsonSource update in the queue.
This pr remove this logic to guarantee all annotation update could be executed.
User impact (optional)