How to optimize the code size of v7 version?

Description

I use v6 and v7 to compare the code size in this git repository.
In this git repository, I placed my modified lv_port_stm32f429_disco v6 and v7 versions of the project.

My modifications are:

  • In lv_conf.h, the animation, anti-aliasing, shadow, group, file system are turned off.
  • In main.c Some examples are called, including btn/dropdown/win/btnmatrix/cont/img/imgbtn/page/roller/slider/line objects.

The size of V6 is 66kbyte, and the size of V7 is 88k, a difference of 22k.

What MCU/Processor/Board and compiler are you using?

STM32F429

What do you want to achieve?

Is there any way to optimize the v7 version so that its code size is approximately equal to V6?

What have you tried so far?

I try to check the macros that can be disabled in lv_confg.h as much as possible to ensure that it is not the difference in code size between v6 and v7 caused by my improper configuration

Code to reproduce

All relevant code is here: https://github.com/liangyongxiang/lvgl_size_compare

Screenshot and/or video

NULL

I think the new style system is expected to increase the code size somewhat. We were optimizing more for RAM usage and performance, since flash space is usually less of a concern.

However, it would be nice to shrink that difference between the two. Can you run arm-none-eabi-nm --print-size --size-sort on your program file and put the results here? That lets us see what the largest functions are. It seems that the vX_function.txt file doesn’t sort the size of the functions.

Another thing to try is disabling extra fonts that you aren’t using.

Can you run arm-none-eabi-nm --print-size --size-sort on your program file and put the results here?

OK. I added these files:

  • vX_function_size_sort_without_grep.txt is the original output.
  • vX_function_size_sort.txt is to filter the output of littlevgl independent functions

In addition, I have uploaded the elf files of these two projects.

Another thing to try is disabling extra fonts that you aren’t using.

In my project, the code rom is only 128k, and the constant data including fonts and pictures are stored in external FLASH.
So here I am not concerned about the size of constant data.

We can’t see the uploaded files.

@kisvegabor They’re in his GitHub repository.

1 Like

Hm, I can’t see anything special. It seems some functions got larger. :frowning_face:

Not a real solution but -Os flag could help a lot and be sure to use

  • -fdata-sections -ffunction-sections compiler flags
  • --gc-sections linker flag

In the previous project, I have configured -Os, gc-sections and -ffunction-sections.
Now I added -fdata-sections to the project, the size of the text section is slightly increased.

Previous size information: https://github.com/liangyongxiang/lvgl_size_compare/tree/607c0de0cb5acf558450000aec9720895c78c0c1
Current size information: https://github.com/liangyongxiang/lvgl_size_compare/tree/92602e5278c11779d21d60d150abbf7aa7c7896f

By checking the makefiles of the projects I couldn’t find Os flag. Maybe I was looking in the wrong place, so just to be sure, are you using Os is case of the v7 project too, right?

Could you attach a line from both compiler outputs where all the flags can be seen?

v6 is using -O3 and -ffunction-sections.

v7 is using the same.

My test results are based on Debug, not Release

I have not added the relevant files in the Debug directory before.
Now I add these files and push them.

In addition, the reason for not using Release is that the compilation is wrong.
I think the difference between Debug and Release is more in predefined macros.
After I confirmed that there was no macro like -DDEBUG in Debug, I compared the size based on it.

With Os I think there won’t be much difference between Debug and Release. :frowning: