MarcusWolschon / osmeditor4android

Vespucci is a OpenStreetMap editor for Android
http://vespucci.io
Other
374 stars 83 forks source link

Major problems with “loading data into memory” – long delays, strange data styling effects and even crashes #2614

Open jajajaneeneenee opened 3 months ago

jajajaneeneenee commented 3 months ago

Vespucci Version

20.1.0 Beta3

Download source

Google Play Store

Device (Manufacturer and Model)

Samsung A33

Android Version

14

Behaviour/Symptoms

I have been experiencing a very annoying issue with very long delays with the message "Loading data into memory" after switching apps or going to and from the home screen for a while (already under Android 13 and Vespucci v19.x, and now under 20.0.x and 20.1.0 Beta3). My first screenshot with the problem is from 2023-08-09. It frequently makes mapping difficult or even impossible when you are on the move. I also tried to use the recent apps list only to go back to Vespucci, but I think (not 100% sure) that this does not help to solve the problem.

Describing and reproducing the problem is not easy, as it does not occur in every case, but very frequently and practically always during a mapping tour - and often it does not stop or I do not know how to stop it (I have tried everything possible). And often it becomes a kind of loop and you can no longer carry on normally. And it always costs a lot of time and energy.

I was hoping that the new fixes in v21.1.0 regarding app launch might resolve this, but unfortunately not. That's why I'm writing this (a little longer …) issue now. Perhaps it's also a special Samsung or a general Android problem? Don't know.

There are several effects of varying severity that, in my opinion, are all related to one another. I will try to describe it (from less severe to worse effects):

Example sequence 1 (without “worst case”, only a long delay up to 20 s, no ANR dialog):

Example sequence 2 (with ANR dialog):

Example sequence 3 (with data styling reset and delay > 60 s):

Just some suspicions/thoughts:

For information:

I have these questions too (among others), maybe you could shed some light on them?

How to recreate

See notes above. I haven't found a reliable way to reproduce it yet, all I can say is that it happens to me pretty much every day when I'm mapping.

Some screenshots

Screenshot_black_screen_with_loading_data_into_memory_and_ANR_dialog Screenshot_loading_data_into_memory_OH_editor

Black screen at startup (for some seconds): Screenshot_black_screen

Minimal data styling (in rare cases): Screenshot_DataStyling_minimal-01

Some debug infos:

Screenshot_debug_info_v19 3 5_2024-03-12 Screenshot_debug_info_v20 0 0_2024-04-12 Screenshot_debug_info_v20 0 0_2024-06-01

Crash dump submitted (no or yes + date)

Yes, several times (I don't remember the dates; I have one crash screenshot from 2024-03-26). I remember adding a text like "Problems after loading data into memory" at least once.

simonpoole commented 2 months ago

Literally everything you list as symptom points to you running out of memory (and we've discussed this before). There is no reason to believe that the changes in 20.1 would improve this, actually pre-loading the NSI will likely make it worse.

And as your last screenshot shows, it isn't the amount of OSM data that is causing the issue (but you are using 60% of the total available memory there with no obvious cause).

Things I would suggest trying:

further check for any settings/functions on your device that could remove vespucci from memory that are available, in general it should be -difficult- to get the app to completely restart (loading the state in to memory essentially only happens then) and should really only be the case if you manually completely exited it.

Check that you don't have the "Don't keep activities" option turned on in the Android developer options.

I would further note that both state files seem to be excessively large in that last screenshot, resetting both the OSM data and tasks now and then after editing and uploading might help with that.

PS: the 0.5 GB maximum memory is the same on all modern Android devices, so there is nothing special about the memory budget for your device, aka mine is exactly the same.

simonpoole commented 2 months ago

Is this crash dump from ~2 weeks ago from you? Its an A33, and the crash is happening on parsing the preset after changing the configuration.

Kommentar
I changed the datastyling (to colour round nodes) and the activated presets (from my custom presets to the Simonpoole beautified preset) in the preferences, then a long black screen, then the crash. I often have problems especially when changing presets, I often have to restart Vespucci after that.
Entschleierter Stacktrace
java.lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 5011664 free bytes and 4894KB until OOM, target footprint 536870912, growth limit 536870912; giving up on allocation because <1% of heap free after GC.
    at libcore.util.NativeAllocationRegistry.registerNativeAllocation(NativeAllocationRegistry.java:270)
    at com.android.icu.util.regex.MatcherNative.<init>(MatcherNative.java:51)
    at com.android.icu.util.regex.MatcherNative.create(MatcherNative.java:45)
    at java.util.regex.Matcher.usePattern(Matcher.java:341)
    at java.util.regex.Matcher.<init>(Matcher.java:209)
    at java.util.regex.Pattern.matcher(Pattern.java:989)
    at de.blau.android.util.SearchIndexUtils.removeDiacriticalMarks(SearchIndexUtils.java:144)
    at de.blau.android.util.SearchIndexUtils.deAccent(SearchIndexUtils.java:133)
    at de.blau.android.util.SearchIndexUtils.normalize(SearchIndexUtils.java:59)
    at de.blau.android.presets.Preset.addToSearchIndex(Preset.java:491)
    at de.blau.android.presets.PresetItem.addValueAndDescriptionToSearchIndex(PresetItem.java:279)
    at de.blau.android.presets.PresetItem.buildSearchIndex(PresetItem.java:219)
    at de.blau.android.presets.PresetParser$1.endElement(PresetParser.java:828)
.....
jajajaneeneenee commented 2 months ago

Is this crash dump from ~2 weeks ago from you? Its an A33, and the crash is happening on parsing the preset after changing the configuration.

Yes, it's mine. I only had such a crash like this one time. I think there was no syntax error in my presets or datastyling when it happened (as far as I can remember). And as I wrote, I deactivated all my files to check something. I don't remember any further details. Except that I was able to restart Vespucci after the crash and there were no particular problems (as far as I can remember). Otherwise I would probably have written a GitHub issue.

simonpoole commented 2 months ago

The point is not that it crashed as a result of the particular action, but that it crashed as the result of an out of memory error. Once you are (so) low on memory such an error can happen essentially anywhere but it underlines that the likely cause of your issues is not enough memory/something using it up very fast.

simonpoole commented 2 months ago

Pro memoria: the NSI seems to currently require ~50MB of memory.

jajajaneeneenee commented 2 months ago

Literally everything you list as symptom points to you running out of memory (and we've discussed this before). There is no reason to believe that the changes in 20.1 would improve this, actually pre-loading the NSI will likely make it worse.

And as your last screenshot shows, it isn't the amount of OSM data that is causing the issue (but you are using 60% of the total available memory there with no obvious cause).

Things I would suggest trying:

* disabling the NSI

* checking the effect of any GPX tracks loaded

* checking the effect of any additionally loaded presets

further check for any settings/functions on your device that could remove vespucci from memory that are available, in general it should be -difficult- to get the app to completely restart (loading the state in to memory essentially only happens then) and should really only be the case if you manually completely exited it.

Check that you don't have the "Don't keep activities" option turned on in the Android developer options.

I would further note that both state files seem to be excessively large in that last screenshot, resetting both the OSM data and tasks now and then after editing and uploading might help with that.

PS: the 0.5 GB maximum memory is the same on all modern Android devices, so there is nothing special about the memory budget for your device, aka mine is exactly the same.

Thank you for all the hints ...

NSI:

To understand it correctly: When "Loading data into memory" appears, is it loading or updating the NSI from the network? That would explain why it is so bad when the network reception is poor (e.g. in dense forest). Is it loading/updating anything else from the network (e.g. OSM notes or Osmose warnings)?

I had "Enable name suggestions" activated + now deactivated (I assume that is what the NSI is used for). "Enable name suggestion prese.." was already deactivated. Will this stop pre-loading the NSI on startup?

GPX tracks:

I have one GPX layer with a self-made GPX file which only contains 24 way points – it has 32 KB. (The debug info says: "GPX 6 GPX true content://com.android.providers.downloads.document/msf%3A1000011300" – but the file name of the GPX file is different). I could delete that layer if it is helpful.

In rare cases I used the GPX recording for a short time, but after that I always used "Delete GPX track and its waypoints". Now, there is no track.

Effect of any additionally loaded presets

I can try to check next time, if deactivating all my (3) custom presets and only use your current "Simonpoole last release" preset (or better only the build in preset?). Or what do you have in mind?

I assume it only loads the activated presets during startup, is that correct?

Normally my 3 presets are:

  1. Something like a fork of your “Simonpoole Beautified Preset” (with custom changes and additions and especially many “shortcut” items with special default values ​​and also for overriding existing tags – I use Javascript in these items). And I changed most of the icons from PNG to SVG to have a nicer rendering in Vespucci ... (and added some custom icons). This works great by the way (and I hope that rendering the SVGs doesn't eat up a high amount of memory, the icon files are of course greater than PNGs in 48x48 px).
  2. A special "lifecycle preset" with many Javascript items to apply lifecycle prefixes with custom changes and also a lot of "Map Icon Display" items to display (custom) lifecycle icons for objects with lifecycle tags (a long object_keys list is required to let them match – matching with REGEX because of the prefixes would drastically reduce this ...). I know, I could also have used datastyling ... but it would also cause a lot of rules in the XML. And with the presets I also have a suitable matching in the properties editor...
  3. A special preset for German traffic signs with all German traffic signs as icons (here as PNGs!) and some complex Javascript elements to generate multiple traffic_sign values ​​one by one (with validation rules etc.). I've thought about releasing this a few times, but it's very Vespucci-focused (with greatly reduced functionality for JOSM as well), and there's no real platform for Vespucci presets yet (like JOSM). That's what's kept me from doing it so far.

Settings/functions on your device that could remove Vespucci from memory

As I wrote, I had already checked everything that came to mind, but this is really a bad thing with Android or the manufacturer's own functions for energy saving and so on ... Some Android settings I use:

Android developer options

I always had "Don't keep activities" option turned off.

But I have to admit that I completely forgot to check the Developer Options. Very stupid ... I had turned them on some time ago (when the problems described were already there) to see if anything could help improve things. I don't remember exactly when I activated it

And stupidly, I had this still activated:

I have now completely turned off the Developer Options for further testing.

(Small side note: although I studied computer science in the late 80s/early 90s, I never worked as a developer or programmer as my main job ... but as a project manager, among other things.)

Memory and state file

Running out of memory: I looked at the debug info several times when the problems occurred and I always saw that "Total memory used" was well below the maximum. I have 6 screenshots with the debug info and the highest value is 322817288. 60% means, that 40% are free – can this really be an OOM? I don't understand it completely why this is a low memory state. I think we already wrote about this, I know ...

What would a "normal" amount of used memory?

And what are the potential candidates for using up the rest of the memory in a fast way (if I don't download new OSM data and all presets/datastyling is already loaded)? Could it have anything to do with Javascript items (I use a lot of them, but most of them only with small and simple Javascript code for setting or removing tags – only my traffic_sign Javascript items are larger and more complex; see infos about presets above)? But could they be responsible for memory not being released properly, for example if they are used frequently?

State file: Is this the file which keeps the downloaded OSM data (and the changes)? In one of the 3 screenshots it's 2584077 (2,5 MB?). Did you mean this with "excessively large"?

Bug state file: What's is stored in that file? And 622480 is also "excessively large"?

Sometimes, I perhaps had downloaded a larger area of OSM data (I try to avoid that), but of course I always use "Clear and download current view" after an upload and if starting with a new area. Or should I also use "Clear data" from time to time (I mean does it clear more data)?

Resetting tasks: I am still a little confused because of the wording and the commands in Vespucci.

Maybe I need a few more days of testing, especially with developer options disabled (and NSI disabled)... And maybe just use your or the internal presets if there are any problems - I don't think there's much I can change/improve to reduce memory usage for example. Then I'll see what happens.

I will write then again. I'm not quite sure if the weather in the next few days will be good enough for a longer mapping tour.

But it would be helpful if you could answer some (or even all?) of my questions in the meantime. Thank you very much!

jajajaneeneenee commented 2 months ago

The point is not that it crashed as a result of the particular action, but that it crashed as the result of an out of memory error. Once you are (so) low on memory such an error can happen essentially anywhere but it underlines that the likely cause of your issues is not enough memory/something using it up very fast.

Ok, I understand this connection.

It certainly fits the situation – it is very likely that I also changed the presets/data styling when there was a problem, to see if it helped. But I can't remember if I had restarted Vespucci BEFOREHAND, for example, and if a lot of OSM data had been loaded and changes had not yet been uploaded, etc. But I'm pretty sure I was busy mapping...

simonpoole commented 2 months ago

Is this crash dump from ~2 weeks ago from you? Its an A33, and the crash is happening on parsing the preset after changing the configuration.

Yes, it's mine. I only had such a crash like this one time. I think there was no syntax error in my presets or datastyling when it happened (as far as I can remember). And as I wrote, I deactivated all my files to check something. I don't remember any further details. Except that I was able to restart Vespucci after the crash and there were no particular problems (as far as I can remember). Otherwise I would probably have written a GitHub issue.

The problem is not just the sum of available memory but if there are blocks of the required size (so very fragmented memory may still lead to an OOM even if you are asking for less than total free memory). But I don't think you are doing anything that "in general" can't work with the memory you have available just that you are triggering something in a way that leads to an issue.

The default preset uses around 20MB and the NSI around 50MB as an indication. Taken as is, that shouldn't be an issue, however presets contain images that need to be converted to Android bitmaps for display (that will increase their size) and I suspect that this might be one of the causes for the issue.

Tasks include all Variants, that is Notes, Maproulette Tasks, OSMOSE, and Todos. Resetting will definitely delete anything held in memory. However if you simply manually run "prune" the Todos will not be affected.

The state files contain a serialized version of the on the one hand OSM data plus undo information and on the other hand the same for tasks. There are further files holding editing state and per layer information, but they are typically not critical. And yes "loading data into memory" is displayed while the state files are being read.

jajajaneeneenee commented 2 months ago

Hello ... thank you. Some more light in the dark.

Just for info:

First experiences yesterday (with Developer Options turned off completely + without NSI in Vespucci); I also choosed "prune" in the task layer and tried to use the recent apps list if possible to return to Vespucci when switching apps.

Then a strange thing (never had this before):

Then I did a device restart to be sure ... Then also "Close all apps" in the recent apps list.

Today (at home, Wifi connection):

What I basically don't understand: When I am experiencing the problems, in one case the system seems to trigger an app restart and in another case not (doing the same actions and app switching) – perhaps a bad Android behaviour, and sometimes I waited very long until "Loading data into memory" does end, and short after that (no upload, no new download of OSM data, not very much editing – not much can have changed with the State files) it ends very quickly ... So what was it doing during for example 30 seconds of "Loading data into memory" (It must be gigabytes that are loaded ...) or was it only because of a bad internet connection?

(And why did it happen also if I used the flight mode without any connection – didn't Vespucci notice this?)

And a question about the suspected OOM problems: I understood the situation with fragmented memory. What I don't know is what do I have to do to get Vespucci started with non-fragmented / clean memory? (E.g.: can a device restart be necessary? Can I keep the downloaded OSM data or do I have to clean it? – Would be bad if in dense forest – could I save it and reload it afterwards? Would this make a difference for the fragmented memory?) I'm just looking for a way to continue mapping in such a situation and what I could try ... (If I could not upload OSM data or download a smaller area because of a lack of internet connection = worst case).

Last questions:

  1. After disabling NSI now, is there any network connection needed which can cause delays if it's bad or missing – when Vespucci is restarted (e.g. when triggered by the system somehow)? I mean when I have already downloaded all the OSM data I need and also the Bing tiles are all there and I would like to do some mapping like in an offline mode, e.g. in dense forest.
  2. Does the value of "Native memory usage" matter in any way? (In one screenshot it's 1063516416 – more than 1 GB?)

I'll be watching what happens more closely over the next few days. If there's anything else I should look out for, please let me know.

simonpoole commented 2 months ago

The 1GB native heap is obviously very large, particularly considering that the app doesn't actually explicitly use it, so those allocations are either made by Android or a library we use, but I'm not aware of any that we use that does that. My suspicion is that that might be image/bitmap related. Wild guess: SVG icons?

The other thing that comes to mind wrt general memory usage is data styling, I can't really see how this could amount to any noticeable amount, but all available data styles are parsed on start up and held in memory.

While behaviour of the app is naturally impacted by bad network connectivity, it shouldn't have any bearing on the issues you are seeing.

PS: as a tendency I would increase the on-device tile cache size from the 100MB you currently have configured if you are in areas with bad connectivity.

jajajaneeneenee commented 2 months ago

Hello ... I haven't done much mapping in the last 3 days, so I haven't been able to test much, just a little in a day.

But first I did some more in-depth research into possible Android and Samsung system settings that could play a role.

And I've known for a while that Samsung is known for having a pretty aggressive battery management system, which includes terminating foreground and background processes. It is quite well documented on https://dontkillmyapp.com/samsung, perhaps you know this site (and the app "DontKillMyApp").

I researched all of this a few months ago, but it's really hard for an end user to decide which settings really help with a problem and what they actually do. Anything but nice...

But what I've now found out and changed, which you might also be interested to know (some if this is Samsung specific):

Maybe interesting for you, or you already know that (?):

And one of my main problems with everything is that Vespucci seems to be restarting over and over again and this start-up process takes so long or too long, sometimes leading to ANR conditions. If that didn't happen anymore, it would be a big improvement (or even solve all problems?).

First experiences with the changed settings (especially on one day, about 3 hours):

Here are some screenshots when the ANR dialog appeared:

Screenshot_20240712_191109_Vespucci-–-ANR-dialog-+-Debug-Info

Screenshot_20240712_191150_Device-care-–-ANR-dialog-+-Arbeitsspeicher

Screenshot_20240712_191405_Settings-–-Vespucci-App-Infos

Here is a final screenshot with the state file > 3 MB: Screenshot_20240713_170243_Vespucci

Otherwise, I have now increased the tile cache to 300 MB (OK?) and set "Max. number of download threads" from 1 to 2 (what is the default value?).

And regarding the data styling and SVG icons (which I use in data styling as well as in my presets): I could possibly replace them with PNGs with 48 x 48 px as a test, even if that would be a bit of work.

And the PNGs really do look much worse ... once you have seen the difference! It would be great if you could use JPGs/PNGs in higher (e.g. double) resolution for high-resolution screens, similar to what is possible in web design. And if scaling the pixel graphics would then be necessary: ​​perhaps it is less memory/processing intensive than SVG processing? Although I actually think that the graphics routines for SVG rendering should be very efficient, but you never know.

Off topic: I also really miss an option to specify the icon size for data styling (as is possible for JOSM) or the proportional rendering of SVG graphics - currently non-square graphics are distorted to a square size...

So much for today ...

simonpoole commented 2 months ago

And regarding the data styling and SVG icons (which I use in data styling as well as in my presets): I could possibly replace them with PNGs with 48 x 48 px as a test, even if that would be a bit of work.

And the PNGs really do look much worse ... once you have seen the difference! It would be great if you could use JPGs/PNGs in higher (e.g. double) resolution for high-resolution screens, similar to what is possible in web design. And if scaling the pixel graphics would then be necessary: ​​perhaps it is less memory/processing intensive than SVG processing? Although I actually think that the graphics routines for SVG rendering should be very efficient, but you never know.

Android does not have any native SVG support, so the only thing we do is render the SVG to a bitmap on device. The way things are done now we allocate a bitmap the size of the SVG render to that and then scale that for actual display. This could very well use a lot of memory if the SVG dimension are large. I'm testing a modification that allocates a smaller bitmap that might help with this potential issue.

jajajaneeneenee commented 2 months ago

For your infomation: I haven’t been able to do any real “stress tests” with longer mapping tours in the last few days. That's why I haven't written anything else.

However, I once had the ANR dialog in a loop again (3 days ago, I was out and about). "Clear data" in Vespucci, restarting Vespucci (small State file after that) and (before) "Clear memory" in the Android settings didn't help either.

Around 10 minutes later (at the same location, only around 50 m away) it started working again. And then for the next 3 hours there was no ANR dialog - despite using other apps, a larger map section was loaded etc. I just can't see any regularity as to when it occurs and when it doesn't.

Once in the evening (at home) I had the phenomenon again with the data styling reset to minimal (black lines etc.), but no ANR dialog! But a fairly large map section was loaded (state file 2.9 MB) ... And I had switched back and forth a lot between different apps, so maybe the Android memory management?

And another piece of information: To test whether it has anything to do with the SVGs, I have now replaced the SVGs with PNGs in all my custom presets and the data styling (which took a day's work) ... However, as I said, I have not been able to test it thoroughly yet, but I will report back as soon as I can say more about it.

So far I haven't had any ANR dialog, and the "Loading presets" process seems to be 1-2 seconds faster (usually about 6 seconds). Of course the preset and datastyling (zip) files are also a bit smaller ...

simonpoole commented 2 months ago

So far I haven't had any ANR dialog, and the "Loading presets" process seems to be 1-2 seconds faster (usually about 6 seconds). Of course the preset and datastyling (zip) files are also a bit smaller ...

The rendering of all icons is on demand, so isn't happening while the preset is being read, but for example while the first map is being displayed.

jajajaneeneenee commented 2 months ago

I have some new information (and some new insights).

First because of replacing all SVGs with PNGs (in my custom data styling and the presets):

New insights (and assumptions) regarding multiple custom data stylings:

This might even be/have been the main problem besides the memory requirements of the rendered SVGs (which by the way are all created in the size 580 x580 px, a few maybe in 600 x 600 px, but not larger).

What happened:

Here is a debug info screenshot (after the import of 4 new custom data stylings):

2024-07-24 Debug Info with full memory after adding 4 data stylings

What I then discovered when reconfiguring Vespucci (v20.1Beta4):

Since then, no major problems (apart from the frequent app restarts). So far, no ANR state, no crash, no minimal data styling. But no very large "stress tests" either...

Main question/assumption after all this:

I now suspect that ALL imported data stylings are loaded into memory when the app starts and are kept there (or when a new one is imported) – at least the styling rules (If the PNGs used in data styling by iconPath="XY" are perhaps also only loaded when needed for the map, like you explained for the display of the icons in the presets?). And not just the currently activated one. I wasn't really aware of that until now, but it would (perhaps) explain a lot.

So the most important question is: is that the case?

It would explain why I had such high memory consumption the whole time and Vespucci became unusable after adding 4 new data stylings, as described above. (Although it is not 100% clear to me why a data styling that is 12 MB unzipped - and only with PNGs - might lead to a memory requirement of 35 or 44 MB (see above), and whether there are opportunities for optimization. But maybe that is not the most important thing.

The big problem is that you can add custom data stylings with "Import data style", but you cannot remove what you have added (there is no "Remove custom data styling" as for presets). I had already noted this in 2022 in #1874 (that a similar interface for data stylings as for Manage Presets would be very desirable), but nothing has changed since then. I will try to create a new issue for it soon, because I think that would be very important. But maybe I am the only Vespucci user who uses custom data styling (or such extensive ones) and who then encounters this problem?

And because that's the case and I hadn't completely reset Vespucci in a long time (reinstall or clear app data), I had a total of 5 custom data stylings for a long time (most with smaller XMLs than my current version, but it would perhaps explain the high memory consumption and OOM situations if the styling rules of all XMLs are kept in memory and these also require significant memory. Plus the SVG problem...)

As long as there is no "Remove custom data styling" function, I will make sure not to import more than my 2 styling variants, i.e. not to assign new profile names. I would of course also like to test with SVGs again as soon as your SVG scaling/rendering change is published (20.1Beta5?), and assume that I can then import an SVG data styling version with the same profile name as the PNG only version. And that I can then change it back again (PNG only) without this resulting in additional RAM usage (perhaps space usage in the internal memory, if SVGs once imported remain there? That wouldn't be a big problem... I don't know if the DataStyling is unzipped when imported and how the handling of graphic files that are no longer used looks like).

Basically, it would be very helpful for me if you could publish a short information about what exactly happens when the app starts and in what order (and what is permanently stored in the RAM or removed again by various commands and functions in the app).

At the moment I can only guess - e.g. because there is no significant delay when you change the data styling (= all stored in memory?), but a clearly noticeable delay when you have changed the preset selection and exit the settings (I suspect that the selected presets are then loaded into memory and deactivated presets are removed from memory, so it doesn't matter whether the list of presets contains many - deactivated - presets, unlike with data styling).

Off topic: By the way, I have just created another issue – #2632 – regarding preset activation/deactivation (or loading a new version), because it would be necessary for the validator to be reinitialized every time the presets are changed. If there are changes in the presets (e.g. if you have made validator check keys optional in preset items), the validator engine will not immediately recognize this; you must first change something in the validator check keys to trigger a re-initialization.

simonpoole commented 2 months ago

Beta 4 contained the changes to SVG rendering https://github.com/MarcusWolschon/osmeditor4android/releases/tag/20.1.0.4 (a 580px X 580 px image corresponds roughly to a 1.3MB bitmap if not scaled down to the target icon size).

In general it isn't possible to definitely document when things are loaded and not, as nearly all of it happens asynchronously to the main UI thread running. More so, garbage collection of objects that have no active references any more is controlled by the JVM, there is no guarantee that memory used by objects that are no longer referenced is immediate (which is likely what you are seeing).

All available data styles are currently held in memory that that shouldn't really be an issue, as the classes should be small, but potentially there might be some references retained in the icon caches when you are switching back and forward which potentially could be improved.

simonpoole commented 1 month ago

Can this issue be closed?

jajajaneeneenee commented 1 month ago

Can this issue be closed?

A good question ... difficult to answer. There are still some things I would like to understand better. And some questions are unanswered.

First of all: the problem has been significantly reduced for me since I stopped using SVGs (instead, PNGs in 48x48px) and only used 2 custom data styling files. I can now map much more relaxed again...

Since then, practically no more ANR states or these "minimal data styling" effects, possibly caused by OOM states.

Problems/open questions that remain include:

  1. Are app startup times between 10 and 20 seconds normal? And why are they sometimes only 10 seconds (sometimes a little less), and then 20 seconds again (sometimes more), with the same amount of data downloaded, etc. It is still a test of patience when you are on the move while mapping. I also wonder WHY it takes so long in the first place (adding a new data styling or updating a preset file is much quicker, for example). Also adding all the used ones again and downloading the OSM data would probably be faster. Do I have to buy a high-end cell phone?
  2. Could this loading time be reduced somehow? For example, by not loading ALL data styling into memory, but only the selected one? Or by other measures?
  3. Do we still have to live with the very frequent app restarts caused by Android? Do you have no influence on this? (My question about the "new foreground service API policy" remains unanswered - see my comment above). Can you say anything about this? For example: This has no meaning in this case. / This is already implemented for Vespucci. / This cannot be implemented for Vespucci. / This would need to be investigated further.
  4. You wrote that the data styling rules should not require a lot of memory (I think so too!), but how can it be that after adding 4 more data stylings, the memory used increases from around 200 MB to over 500 MB, and Vespucci is practically no longer usable? (See my comment and screenshot above).
  5. I would like to test this again, and also see how it behaves with SVGs, but the effort of having to completely reset Vespucci and reconfigure everything is very high. If my feature request #2631 would be implemented, it would be much easier and would help to close this issue (and maybe provide further insights).
  6. At what resolution are the SVGs rendered after your change (also only 48x48px)? I'm asking because I'm interested to know whether SVGs will continue to be displayed better than PNGs.
  7. Would it be interesting for you if I did another test with the SVG variants (of data styling and presets)? Even if that could mean resetting the app again. (A backup/restore function for all settings would be great ...)
  8. Would it be interesting for you if I sent you my custom data styling (via private email or similar) including SVGs and PNGs? And possibly also my custom presets? I don’t want to publish this (yet).
simonpoole commented 1 month ago
1. Are app startup times between 10 and 20 seconds normal? And why are they sometimes only 10 seconds (sometimes a little less), and then 20 seconds again (sometimes more), with the same amount of data downloaded, etc.  ...

Except for "cold starts" aka the app was previously terminated and removed from memory, switching to the app should be nearly instantaneous. Reading the saved data state is typically only an issue if the system needs to garbage collect while doing so. There is a specific aspect that likely mainly effects you, that the data styles are currently not read asynchronously on start up, so if you have a lot of them that might be an issue (I'm refactoring the relevant code so there might be some improvements there, however the styles need to be available before the data is rendered so that will always a bit of a limit on things).

2. Could this loading time be reduced somehow? For example, by not loading ALL data styling into memory, but only the selected one? Or by other measures?

3. Do we still have to live with the very frequent app restarts caused by Android? Do you have no influence on this? (My question about the "new foreground service API policy" remains unanswered - see [my comment above](https://github.com/MarcusWolschon/osmeditor4android/issues/2614#issuecomment-2231002175)). Can you say anything about this? For example: _This has no meaning in this case. / This is already implemented for Vespucci. / This cannot be implemented for Vespucci. / This would need to be investigated further._

In general the app never restarts for me (same Samsung OS Android version), aka I have to explicitly exit completely to make that happen. Things you can check are for example the background battery usage setting for the app.

The app has always fulfilled any google set policy restrictions etc for services/background use and this is no different, the new policy requires apps to explicitly require a subject matter specific permission for foreground services (instead of an unspecific one) but that is just about being able to run the service in the first place (which just affects GPX recording BTW).

20.2 has an option to enable "hardware" rendering which allows bitmaps etc to be stored in memory outside of the Java VMs heap which may or may not help with your issue, but at least in principle makes more memory available to the app.

4. You wrote that the data styling rules should not require a lot of memory (I think so too!), but how can it be that after adding 4 more data stylings, the memory used increases from around 200 MB to over 500 MB, and Vespucci is practically no longer usable? (See [my comment and screenshot above](https://github.com/MarcusWolschon/osmeditor4android/issues/2614#issuecomment-2253533347)).

Simply adding additional data styles should not use any significant amount of memory (I would suspect perhaps 1kB per feature entry so, ~0.5-1MB per style), switching between them if they have many custom icons will cause more use because of caching of icons etc, till the system re-runs garbage collection.

5. I would like to test this again, and also see how it behaves with SVGs, but the effort of having to completely reset Vespucci and reconfigure everything is very high. If my feature request [Add a function to remove custom data stylings  #2631](https://github.com/MarcusWolschon/osmeditor4android/issues/2631) would be implemented, it would be much easier and would help to close this issue (and maybe provide further insights).

See my comment on the relevant issue.

6. At what resolution are the SVGs rendered after your change (also only 48x48px)? I'm asking because I'm interested to know whether SVGs will continue to be displayed better than PNGs.

The map icons are 20x20 dip iirc. PNG are scaled down to that size, so likely SVG rendering to that size will still be better.

7. Would it be interesting for you if I did another test with the SVG variants (of data styling and presets)? Even if that could mean resetting the app again. (A backup/restore function for all settings would be great ...)

See Add a function to remove custom data stylings #2631

8. Would it be interesting for you if I sent you my custom data styling (via private email or similar) including SVGs and PNGs? And possibly also my custom presets? I don’t want to publish this (yet).

Yes.