Giter Club home page Giter Club logo

Comments (12)

headupinclouds avatar headupinclouds commented on May 13, 2024

See: https://wiki.wxwidgets.org/Reducing_Executable_Size

"Pass -ffunction-sections -fdata-sections to the compiler while building and -Wl,--gc-sections to the linker"

Create a toolchain file that compiles the library and all Hunter dependencies with:
-ffunction-sections -fdata-sections

And be sure to link with

  CHECK_C_COMPILER_FLAG("-Wl,-dead_strip" FLAG_dead_strip)
  IF(NOT FLAG_dead_strip)
    SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--gc-sections")
  ELSE()
    SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,-dead_strip")
  ENDIF()

http://stackoverflow.com/a/18115676

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

Also -flto might help
http://stackoverflow.com/a/31355020
GCC: https://gcc.gnu.org/wiki/LinkTimeOptimization
Clang: https://llvm.org/docs/LinkTimeOptimization.html

from drishti.

ruslo avatar ruslo commented on May 13, 2024

Another options:

  • Try -O2 instead of -O3
  • Try -Os (MinSizeRel)
  • Single Compilation Unit. This is something that is not implemented in CMake so just for the record.

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

DELETE

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

DELETE

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

http://stackoverflow.com/a/18949281

    XCODE_ATTRIBUTE_GENERATE_MASTER_OBJECT_FILE "YES" # "Perform Single-Object Prelink"

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

I've added a lightweight c interface (remove rtti, etc) and strip everything except the explicitly defined symbols table (details below) and can get the sdk down to 2.2 MB from the previous 8.0 MB. This is also using a new xcode-sections toolchain for all hunter dependencies.

6.9M _install/xcode-sections/lib/libdrishti.0.7.1.dylib
4.0K _install/xcode-sections/lib/libdrishti.0.dylib
4.0K _install/xcode-sections/lib/libdrishti.dylib
2.2M _install/xcode-sections/lib/libdrishti_c.dylib
792K _install/xcode-sections/lib/libdrishti_c.dylib.gz

function(drishti_hide_and_strip drishti_library)
  set_target_properties(${drishti_library}
    PROPERTIES
    CXX_VISIBILITY_PRESET hidden  ### HIDE
    VISIBILITY_INLINES_HIDDEN "ON"
    XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN "YES"
    XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "YES"
    XCODE_ATTRIBUTE_COPY_PHASE_STRIP "YES"
    XCODE_ATTRIBUTE_STRIP_INSTALLED_PRODUCT "YES"
    XCODE_ATTRIBUTE_STRIP_STYLE "non-global"
    XCODE_ATTRIBUTE_STRIPFLAGS "-x -u -r"
    XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING "YES"
    XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES"
    XCODE_ATTRIBUTE_GENERATE_MASTER_OBJECT_FILE "YES" # "Perform Single-Object Prelink"
    PUBLIC_HEADER "${DRISHTI_DRISHTI_HDRS_PUBLIC}"
    )
endfunction(drishti_hide_and_strip)
  drishti_hide_and_strip(drishti_c)

  set_target_properties(drishti_c
    PROPERTIES
    XCODE_ATTRIBUTE_EXPORTED_SYMBOLS_FILE "${CMAKE_CURRENT_LIST_DIR}/drishti/drishti_symbols.txt"
    )

drishti_symbols.txt:

_drishti_create_from_file
_drishti_create_from_stream
_drishti_destroy
_drishti_segment

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

Switching to MinSizeRel and dropping the unnecessary text archive support on OS X saves a bit more:

5.9M libdrishti.0.7.1.dylib
4.0K libdrishti.0.dylib
4.0K libdrishti.dylib
1.9M libdrishti_c.dylib
716K libdrishti_c.dylib.gz

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

This stripped _c.dylib.gz size is suitable. The issue can be closed once the post build install() libraries are actually tested. See #75

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

See #138

This is really an ongoing effort. The eye sdk size is significantly reduced using the above C interface, and initial comparisons were done in #138, so I'm removing this from the current milestone in favor of more focused follow up efforts.

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

Some Apple notes on size reduction "How to best..."
https://developer.apple.com/library/content/technotes/tn2185/_index.html

from drishti.

headupinclouds avatar headupinclouds commented on May 13, 2024

This was on the right path but was missing: -flto -Os and related per platform linker flags (as needed) to get the full savings. Satisfied with current approach after boost -> cereal updates + extern "C" api + strip + -flto -Os -fdata-sections -ffunction-sections

from drishti.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.