house-of-abbey / GarminHomeAssistant

Garmin application to provide a dashboard to control your Home Assistant
https://community.home-assistant.io/t/home-assistant-app-for-garmin/637348
MIT License
100 stars 14 forks source link

Look for memory usage efficiencies #87

Closed philipabbey closed 9 months ago

philipabbey commented 9 months ago
  1. Removal of debug
  2. Removal of RezStrings class in favour of inlining.

Anything else?

philipabbey commented 9 months ago

On some devices it looks like removing the System.println() statements from inside an 'if' clause whose condition is a constant (static constant Globals.scDebug) makes a memory saving. This would suggest the compiler does not propagate constants and prune unreachable code. However in the device of greatest interest debug removal has made no difference to the memory usage. Here the conditional clauses have been turned into comments that can be removed on a case-by-case basis otherwise the debug printing is too voluminous anyway.

philipabbey commented 9 months ago

It is the menu construction with mHaMenu = new HomeAssistantView(menu, null); that causes the widget to crash due to an "out of memory" error. The HTTP GET request just before it returns just fine, and the memory usage before the crash is 80% of 60 kB.

Before menu construction: used = 49144, total = 61376, 80.070389%
philipabbey commented 9 months ago

Removing RezStrings.mc and inlining the code can save 1,096 bytes from the application.

philipabbey commented 9 months ago

Stating the obvious perhaps, but we must also remember that caching a menu also takes up memory, so increasing the risk that the Widget version crashes out of memory.