Skip to content

cpp binary size #74

Description

@joprice

I was surprised to find the optimized size of the binary that simply prints hello was 4.3M. A similar program in cpp is 12K, go is 1.2M. I inspected the output folder and the Makefile to see what was being built, and after wading through a sea of segfaults, I narrowed down the SRCS variable to just what was needed:

  SRCS := $(call rwildcard,$(CC_SRC)/Main/,*.cpp)
  SRCS += $(call rwildcard,$(CC_SRC)/Data_Show/,*.cpp)
  SRCS += $(call rwildcard,$(CC_SRC)/Data_Symbol/,*.cpp)
  SRCS += $(call rwildcard,$(CC_SRC)/Record_Unsafe/,*.cpp)
  SRCS += $(call rwildcard,$(CC_SRC)/Effect_Console/,*.cpp)
  SRCS += $(call rwildcard,$(CC_SRC)/Type_Data_RowList/,*.cpp)
  SRCS += $(call rwildcard,$(CC_SRC)/purescript.cpp)
  SRCS += $(call rwildcard,$(FFI_SRC)/console/,*.cpp)
  SRCS += $(call rwildcard,$(FFI_SRC)/unsafe_coerce/,*.cpp)
  SRCS += $(call rwildcard,$(FFI_SRC)/prelude/,*.cpp)

With this change, the resulting binary is 368k. This is a much more attractive base size, especially for using for small utilities like kubernetes services, but also other applications like an ios game targeting objc++.

The Makefile currently uses spago sources to figure out what dependencies to build corefn for. Would it be possible to do soemthing similar to narrow down the SRCS as well?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions