bryceco / GoMap

OpenStreetMap editor for iPhone/iPad
ISC License
301 stars 40 forks source link

Prepare for Offline Stalls UI Thread #759

Closed Alex-Vasile closed 1 month ago

Alex-Vasile commented 1 month ago

The current implementation of the "Prepare for Offline" hangs the whole UI when it's pressed for a few seconds (I assume it's gathering which tiles need to be downloaded).

I closed the app the first 2 times this happened thinking that it had frozen.

I don't know how difficult it would be to implement, but I think a better approach would be to open the download view when "prepare for offline" is pressed, do the calculations on a background thread, show "Calculating..." on the "Aerial Tiles" and "Mapnik Tiles" while the calculation is happening and switch that out for the number of tiles that need downloading when the background thread finishes.

Related to this is that the number of tiles listed does not take into account those already downloaded. Hitting "prepare for offline" downloading all the tiles listed, going back, and hitting "prepare for offline" again will show the same number of tiles that need downloading. When I hit start, the number immediately goes to 0 since it correctly does handles already downloaded tiles at this point.

bryceco commented 1 month ago

Even on my old iPhone 5S the delay is under a second. But I made it asynchronous anyhow.

The code does account for tiles that are already downloaded, not sure why you see something different.

Alex-Vasile commented 1 month ago

Even on my old iPhone 5S the delay is under a second. But I made it asynchronous anyhow.

That's very strange. I opened the issue since it was taking that long on my iPhone 13 Pro, not as an abstract issue.

The code does account for tiles that are already downloaded, not sure why you see something different.

It seems to be working now, not sure why it was acting up in the past. The above issue is definitely actually happening.

bryceco commented 1 month ago

That's very strange. I opened the issue since it was taking that long on my iPhone 13 Pro, not as an abstract issue.

I figured it out: The stall happens when we read the disk to see what is already cached. On my 5S I had recently reinstalled the app so there wasn't anything to read. On a device with a ton of imagery already downloaded there will be a longer wait. Also if the OS filesystem cache is already warmed up then it will be much faster.