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


#1

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

From MicroEJ, go to Help > Help Contents > Memory Map Analyzer User Guide for more info on this tool.

You can also take a look at the following link :

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 section 13.3.4 Display Element in the MicroEJ Device Developer’s Guide for more info on system fonts.

Character ranges

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

  • on font creation
    • see section 13.8.2.4.5 Removing unused characters in the MicroEJ Device Developer’s Guide for more info on how to achieve that
  • on application build
    • see section 3.3.7 Fonts in the MicroEJ Standalone Application Developer’s Guide for more info on how to achieve that

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 3.3.7 Fonts in the MicroEJ Standalone Application Developer’s Guide for more info on how to achieve that.

External Storage

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

See section 13.8.1.9 External Resources in the MicroEJ Standalone Application Developer’s Guide for more info on how to achieve that.

Textual elements

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

See section 12 Native Language Support in the MicroEJ Device Developer’s Guide for more info on 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 section 13.8.1.9 External Resources in the MicroEJ Standalone Application Developer’s Guide for additional info on external ressources management.

Compression

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

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 13.7.1.4 External Resources in the MicroEJ Standalone Application Developer’s Guide for more info on how to achieve that.