[Flash][Footprint] How to reduce the memory footprint of an application

EDIT 09.06.2020: updated documentation links to https://docs.microej.com/

First of all, by using the Memory Map Analyzer plugin, you can get details on the distribution of the footprint of your MicroEJ application.

For more details on this tool, you can consult Memory Map Analyzer — MicroEJ Documentation.

Once you have identified which elements are the most consuming, you will need to reduce their footprint. Here are a few tips on how to achieve that depending on the kind of resource to optimize :

Classpath

  • Make sure to remove any unused Java libraries from the project classpath

Fonts

Removing the default font from the platform configuration

By default, in the platform configuration project, a so-called system font is declared inside the microui.xml file.

When generating the platform, this file is copied from the configuration project to the actual platform project and will later on be converted to binary format and linked with your Java application, even if you use fonts that are different from the system font.

You can therefore comment the system font from the microui.xml file to reduce the flash footprint of your Java application if it does not rely on the system font. Note that you will need to rebuild the platform and then the application to benefit from the footprint reduction.

See https://docs.microej.com/en/latest/PlatformDeveloperGuide/static_init.html#display-element for more info on system fonts.

Character ranges

When creating a font, reduce the list of characters embedded in the font either :

Pixel Transparency

You can also make sure that the BPP encoding used to achieve transparency for your fonts do not exceed :

  • The maximum alpha level of your display device
  • The required alpha level for a good rendering of your font in the application

See section MicroEJ Classpath — MicroEJ Documentation for more info on how to achieve that.

External Storage

To save storage on FLASH, fonts may be accessed from external storage.

See section https://docs.microej.com/en/latest/PlatformDeveloperGuide/fontGenerator.html#external-resources for more info on how to achieve that.

Textual elements

MicroEJ provides the Native Language Support (NLS for short) library to handle internationalization.

See GitHub - MicroEJ/Example-NLS: This example shows how to print a localized string on a display. as an example of use of the NLS library.

You can of course use your own internationalization library if you want. Whatever internationalization library you use, the tips below may be relevant to the footprint optimization domain.

External Storage

The default NLS implementation fetches text resources from internal flash, but you can replace it with your own implementation so as to fetch them from another location.

See External Resources Loader — MicroEJ Documentation for additional info on external ressources management.

Compression

The default NLS implementation relies on text resources that are not compressed, but you can replace it with your own so as to load them from compressed resources.

Images

Encoding

If you are tight on FLASH memory but have enough RAM and CPU power to decode PNG images on the fly, consider storing your images as PNG resources.
If you are in the opposite configuration (lots of FLASH, but little RAM and CPU power), consider storing your images in raw format.

See section 13.7.2 Image Generator in the MicroEJ Device Developer’s Guide for more info on how to achieve that.

Bits Per Pixel (BPP)

Make sure to use images with a color depth not exceeding the one of your display device so as to avoid :

  • wasting memory
  • rendering differences between the target device and the original image resource

External Storage

To save storage on FLASH, images may be accessed from external storage.

See section External Resources Loader — MicroEJ Documentation for more info on how to achieve that.