StreetComplete icon indicating copy to clipboard operation
StreetComplete copied to clipboard

Improve performance on upload: Notice if nothing changed

Open westnordost opened this issue 2 years ago • 0 comments

Current behavior

Whenever the map data changes (download, upload) or the user creates or deletes a local edit, MapDataWithEditsSource notifies its listeners about the changed map data.

Most notably amongst the listeners is the OsmQuestController which will re-scan the changed element(s) for quests and in turn triggers the map to refresh displaying the quests. This is done for example when the user answered a quest and it takes relatively long (a few hundred milliseconds up to a second or so).

After an edit has been uploaded, the copy of the original OSM element is updated and the edit is deleted. This triggers MapDataWithEditsSource to rebuild the cache (=the local changes applied to the original OSM map data) and in turn triggers notifying the listeners about changed.

The Issue

If the element the edit has been applied to and uploaded has not been changed in the meantime by someone else, which consistitutes about 99% of the times,

  • the previous original OSM element + applied edit
  • and the updated OSM element after upload

are identical. In the case that the element didn't change at all, notifying the listeners that the map data changed is superfluous and could theoretically be avoided. Currently it is not avoided, which means not only are the local changes rebuilt on upload of each singular edit (I think this is not avoidable) but that updated element is scanned for quests plus the map being updated as a consequence of scanning for quests. Again, for each singular edit.

At least what could be done is to reduce the number of elements for which the listener is called to those elements that actually changed. This requires to compare the edited elements before rebuildLocalChanges has been called with the edited elements after it has been called.

Challenges

  • since edits and OSM elements are managed independently (MapDataController, ElementEditsController) and thus updating one and deleting the other during upload theoretically constitutes of two separate operations, it is possible that MapDataWithEditsSource is actually notified of a change in data twice for the same uploaded element. Needs to be confirmed is this actually the case

Remarks

If you intend to look into this, post here first because @Helium314 vaguely registered interest to busy himself with it before.

westnordost avatar Jun 03 '22 15:06 westnordost