-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
Use older locations to check whether user has been on site #4947
Conversation
marked as draft per "This is not yet tested" |
In general it looks like a nice idea. Maybe even more than a minute would be nice? But that can be changed later. For performance: How many positions are there typically? 1000? Millions? AKA, how often onLocationChanged is called? I think that bigger danger for performance is in constant maintaining such list of recent locations, not in check run on solving quest. But it is kept for GPS trail anyway. That makes me ask: why separate list of locations is maintained here? Would it be possible to reuse what is kept to draw GPS trail? Or would it be more complicated. |
My device produces at best one GPS location per second, so it would not be more than 60. But maybe more modern devices can do faster updates. Easiest improvement would be ignoring locations close to the previous one as part of
No, because the trail requires accuracy of 20m. |
Then worrying about performance impact of checking all of them seems not needed |
Hmm, a few comments regarding this:
(3. |
Hmm I see, so there is quite a bit more work necessary than I had expected... (if anyone is interested, feel free to take over) |
Current ideas (assuming we want at least 10 m between locations)
|
Uhh, rather not. Or if at all, then everywhere. And that doesn't change that adding a new latlon would still be O(n) time complexity. Actually, what would work to make time complexity I think O(log n) is to use a quadtree to sort the coordinates (i.e. go one level deeper if more than X points are in the same leaf). But, I don't think it is worth the time it to implement this. I think the most straightforward solution would be to not add a new latlon to the list of recent locations if it is closer than max-survey-distance/2. Going forth and back - so be it. |
Some performance test with the current version: |
100ms is definitely far in the acceptable range, since you also tested this on older hardware and this is only done on an UI interaction. I do wonder if it makes sense to have both an upper limit for minutes and also for number of locations? Just to catch absurdly high number of locations checked when one uses the app on the motorway or something. |
The maximum number of locations for the survey distance check is currently 120 (locations of the last 600 seconds, and at least 5 sec between locations). |
This confirmation dialog is the most annoying part of StreetComplete by far; I wish I could turn it off permanently. A simpler solution for most of the false positive warnings would be to trigger the warning based on the location I clicked the quest instead of the location I have moved to when I completed the quest. |
@endolith (and other people of course) if you wish to try out how well does this PR solves the issue (to give feedback), you can try this debug APK https://github.com/mnalis/StreetComplete/actions/runs/5101411056 (my fork also changes a few quests slightly to be shown in little more places, but should not affect the experience regarding this issue). |
Isn't "a list of recent locations" already kind of a thing with the GPS trace that's recorded? #2209 |
Any reason this is still a draft? All remarks / requests for change seem to be resolved. |
There was some reason this wasn't usable, maybe because this only records high accuracy locations, iirc 15 m and better. On a train I usually have accuracy much worse than that.
"This is not yet tested for the actual intended use case" still applies (I would only ever need that PR on a car or train ride, and still didn't test it there), and that was the reason to convert it to a draft. |
@matkoniecz do you consider this tested enough, so this PR can leave draft status? |
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.
I am sorry, it seems I missed that you requested my review.
RecentLocationStore
should probably rather go into data/
as it has nothing to do directly with the UI (and so does part of CheckIsSurvey
but this is not up to you to clean that up 🤷 ).
app/src/main/java/de/westnordost/streetcomplete/screens/main/RecentLocationStore.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/de/westnordost/streetcomplete/screens/main/RecentLocationStore.kt
Outdated
Show resolved
Hide resolved
I only can remember that I did some performance tests, but not what exactly. |
Just in |
Yes |
It should have its own folder in Hm, did you not read my comment? With the current implementation, not only is the whole list of recorded position copied each time a change is made (even for positions that are basically on top of each other), but these calculations need to be done on each edit. And this on the UI thread IIRC, or at least, blocking further interaction on the UI thread, which should come down to the same. Also, I noted another possible performance issue. Once the first locations are old enough for recentLocations.removeAll {
it.elapsedRealtimeNanos <= location.elapsedRealtimeNanos - LOCATION_STORE_TIME_NANOS
} to do anything, it will be done on every adding of a new location (each second?). I.e. each second, the whole array is being re-created (because removing element(s) not at the end of the array does that). Re-allocation of a new array is probably cheap, but it could be avoided entirely by changing from a time-based cut-off (10 minutes) to a number-of-locations-based cut-off and using a ring buffer as the underlying data structure instead of an arraylist. |
Which one? The previous commit was done to address:
Now the whole Or do you mean the testing part? Isn't it enough that for the planned use case the difference to the spherical counterpart is always less than 1 m? Or do you mean
I could do this, but then again this strikes me as premature optimization, as you already said the measured 100 ms are acceptable (done without copying the list using
This again is something I don't really understand. Performance even for complex geometries and on old phones is acceptable, but now should be optimized more?
While I agree that things could be optimized, again there is the question why, as the performance was acceptable already before optimizing the by far slowest part. So in summary, I'm quite confused by the reason for demanding further optimizations. Do you plan to make changes like increasing Anyway, all this feels like it's going to to eat more time, and like it's not going to end anytime soon... maybe @mnalis or someone else who is actually interested in this feature wants to take over? |
Sorry, it looks like you poured much more thought and time into it than I. I wasn't aware that you already tested the different approaches in terms of time. Also, it seems it came across as demanding you change it. That was not my intention, I was just not sure whether you saw the comment I linked to because I answered after you collapsed the thread as resolved. With 100 positions you came out with the 100ms, so for a session that runs 10 minutes or more, it will be ~120ms. This would be a noticeable delay for the user but I understand the move to the flat earth math made something like 10 times faster, so this is completely fine, then.
More like O(n*m), Checking if a way of n segments is within survey distance of last m positions. Will review now. |
app/src/main/java/de/westnordost/streetcomplete/util/math/FlatEarthMath.kt
Show resolved
Hide resolved
app/src/main/java/de/westnordost/streetcomplete/data/location/RecentLocationStore.kt
Outdated
Show resolved
Hide resolved
Thanks for clarifying, I had the impression you meant n² with n positions. Large number of segments definitely is what has most potential to slow down things, but it should be much better now.
Actually this is (of course) on my S4 Mini, and happens only for complex geometries (many arcs for
That was my feeling, thank you for clarifying. Assuming the test doesn't reveal any issues, the current approach should be fine for the planned 10 minute storage. But in case you want it extended for longer times / only limit to a number of locations, your suggestion is definitely preferable. |
test updated to also cover this case
Co-authored-by: Tobias Zwick <[email protected]>
The survey distance check for 100 locations and a building with 70 segments takes around 35-50 ms. Not as much improvement as I had expected, but I don't know which building I had tested on previously. And maybe the debug version is slower than the release version. |
Yeah, the debug version is definitely slower. Does sound very good though, I assume only a tiny amount of elements will have that many segments. |
fixes #4727
Keeps a list of recent locations (within a minute of most recent location update), and uses them for
checkIsSurvey
.The most recent one is checked first, so I would not expect any noticeable performance impact for most users.
If a user has been on site recently, a slower check is still considerably faster than clicking ok in the dialog.
Some performance optimizations are possible, but likely not worth the effort. It only could make things worse for users who haven't been on site recently, but even then: the check isn't that slow.
This is not yet tested for the actual intended use case, will do if the PR is acceptable otherwise.
displayedLocation
is now unused and could be removed from the listeners.