How to reduce code size of iPhone app?

前端 未结 2 1058
温柔的废话
温柔的废话 2021-02-05 23:43

My iPhone app is getting ready to go to production and we like to cram in as much data as possible. When I poke around the generated .app file for my application I see a file n

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 00:31

    There are a number of things you could do -- 2.5 MB is a small app.

    • One obvious way is to verify that your binary is in fact stripped. This removes unused references (e.g. functions which are not actually called) and debugging info.

    • Link Time Optimization (LTO) can save you a ton of space, although that applies to the C and C++ aspects of your program. It brought one of my programs down to about 1/5 the size.

    • Play with optimization settings. O3 and O2 often produce a smaller binary than Os.

    • Keep track of your dependent libraries. Their exported symbols may be relatively large.

    • Favor C or C++ for shared libraries in larger projects. If unused, they may be stripped or optimized away.

    • Minimize static data and static functions, restricting their scope to the c, cpp, m, mm file.

提交回复
热议问题