Bug 404621 - Compress the runtime files for saving space of embedded target
Summary: Compress the runtime files for saving space of embedded target
Status: RESOLVED FIXED
Alias: None
Product: Mihini
Classification: IoT
Component: Agent (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 0.9 M1   Edit
Assignee: Romain Perier CLA
QA Contact: Robert Jacolin CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-29 13:37 EDT by Julien Vermillard CLA
Modified: 2013-05-22 10:57 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Vermillard CLA 2013-03-29 13:37:47 EDT
Actually a lot of flash space is used by the lua source files and non-stripped binaries.

At the end of the build, it would be great to be easily able to compress the file (stripping comments, white-space etc..) and stripping binary files.

As a common use case a doc or an integration in the build system would be nice.
Comment 1 Romain Perier CLA 2013-04-05 05:38:14 EDT
Work in progress. Building the project using "-Os" and "-s" CFLAGS reduces the runtime size from 3 Mo to 2.2 Mo.

Apparently, some libs are linked statically, we can improve this part. I will investigate.
Comment 2 Benjamin Cabé CLA 2013-04-05 05:48:03 EDT
Cool!
Would be nice to remove comments & extra whitespaces from Lua source files too, AFAIR it can save a lot of space (think of all the EPL headers in all the files!)

I used to use this basic regexp (which probably can mess up the sources in some cases ;-))
find . -type f -name '*.lua' -print0 | xargs -0 sed -i '/^[ \t]*--/d'
Comment 3 Laurent Barthelemy CLA 2013-04-05 08:20:59 EDT
Finding, listing, documenting all the ways to reduce "flash" usage is definitely something we need to do.

However, what I am not sure about is the final expectations here: for example I wouldn't reduce debug infos provided by the "default" cmake target settings, especially for the Lua files content.

I would rather provide very precise commands to achieve every ways to reduce flash usage.
To make that "out of the box" I would rely on Cmake settings.

Cmake comes with build profiles/types:
http://www.cmake.org/cmake/help/v2.8.0/cmake.html#variable:CMAKE_BUILD_TYPE


I think we could configure MinSizeRel profile to do everything we've found to reduce flash usage.
We should also discuss this topic in a Wiki page, giving example how to force this Cmake build profile.
But I would leave our "default" Cmake target settings to use the current settings.

Does that sounds good to you guys?
Comment 4 Benjamin Cabé CLA 2013-04-05 08:25:08 EDT
(In reply to comment #3)
> I think we could configure MinSizeRel profile to do everything we've found
> to reduce flash usage.
> [...]
> Does that sounds good to you guys?

Yup. +1 for putting these settings in the MinSizeRel profile. Makes much sense.
Comment 5 Romain Perier CLA 2013-04-08 09:03:11 EDT
Fixed with commit http://git.eclipse.org/c/mihini/org.eclipse.mihini.git/commit/?id=b15ace6ac6f432c32f7b96b531f3322e47294f8b

I have also updated the README.md.

Steps for using this feature :
$ git pull
$ bin/build.sh -m

Enhancement is around 56% here  for x86_64 (3 MB -> 1.7 MB). However depending on the toolchain and the target used, it be might different in size.
Comment 6 Romain Perier CLA 2013-04-08 09:05:14 EDT
Well... that's not 56% (my bad) but enhancement is good anyway :D
Comment 7 Romain Perier CLA 2013-04-08 09:13:10 EDT
Another enhancement might be compressing Lua modules with an lzma compressor and patch the Lua VM to uncompress these modules on the fly. However, it requires a lot of work, and change a standard Lua VM to do that is not really recommended, imho.

Improvement is left for future discussions...