janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.45k stars 223 forks source link

Binary more than 2 times larger with Janet 1.29.1 than with 1.28.0 on Linux #1232

Closed strika closed 1 year ago

strika commented 1 year ago

I noticed something when working on a CLI hobby project implemented with Janet. The binary that I get when running jpm build on Linux is 784KB with Janet 1.28.0 and 1.8MB with Janet 1.29.1, without any code changes.

I created a test repository with a "hello world" application and a Docker configuration and I get the same results. The produced binary is more than twice as large on Janet 1.29.1 than on 1.28.0.

Am I doing something wrong?

It seems to me that this doesn't affect MacOS, though. I built Alas on MacOS with Janet 1.29.1 and I got a binary around 725KB, which is slightly smaller than with 1.28.0.

I also noticed that assets shipped with Janet official releases got bigger with 1.29.1:

Is there an issue here? Or is there a simple explanation of the situation?

bakpakin commented 1 year ago

This is unusual. Can you check if the binary is stripped in the new and later versions? Running 'strip' on both binaries should yield comparable results if that is the cause of the bloat

strika commented 1 year ago

I tested this with the test repository that I mentioned.

With Janet 1.28.0, before running strip, the binary was 748KB. After running strip it's 690KB.

With Janet 1.29.1, before running strip, the binary was 1.8MB. After running strip its 710KB.

CosmicToast commented 1 year ago

My guess would be that it's related to this commit. Can you try running strip with the options -x -S in both cases?

strika commented 1 year ago

I get slightly different resulst:

CosmicToast commented 1 year ago

Okay, that more or less confirms that stripping isn't happening.

CosmicToast commented 1 year ago

Can reproduce on linux x86 but not on mac aarch64. I'm noticing a few things:

  1. build/c/shell.c has been seemingly removed post bootstrap in 1.29.1
  2. -g is passed to post-bootstrap cc in 1.29.1

If I override CFLAGS=-O2 when building 1.29.1, I get an output size of 772k. The following patch also does the trick:

diff --git a/Makefile b/Makefile
index c6be5487..2a3638d7 100644
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ SONAME_SETTER=-Wl,-soname,
 # For cross compilation
 HOSTCC?=$(CC)
 HOSTAR?=$(AR)
-CFLAGS?=-O2 -g
+CFLAGS?=-O2
 LDFLAGS?=-rdynamic
 RUN:=$(RUN)

Note that -g is already present at the end of BOOT_CFLAGS, as of a later commit. Whether removing the -g from the common/system CFLAGS is the right approach, I'll leave up to @bakpakin (as the maintainer). But this is the actual reason this happens.

bakpakin commented 1 year ago

Fixed in 080b37cb3128c1cc5a3912476892c2444930fc71