-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to disable output entirely #721
base: master
Are you sure you want to change the base?
Conversation
This is mostly useful in environments where printf adds a non-negligible amount of code (for example, WebAssembly in the browser). Disabling all output shrinks the binary. Of course, this option should not be used when testing/debugging the GC. I didn't test the binary size difference on WebAssembly, but on Linux (arm64) with a statically linked musl libc the difference is 20kB in my setup.
Okay! |
BTW. Could you please reference your project where the feature is needed? |
I'm using this library in TinyGo. Right now we only use bdwgc on Linux, MacOS, and Windows (where binary size doesn't matter a lot), but I'm working on WebAssembly support. For WebAssembly I'd like to keep binary size down as much as possible. |
Maybe this library could even be used baremetal? That would be interesting to investigate. Our own GC is kinda slow. For baremetal (microcontrollers mostly), binary size matters even more. |
Yes, it should be possible, but I've not heard of such experiments. See NOSYS macro. |
Off-topic: BTW, ages ago my record was a 55KB Win23 executable containing a GC java benchmark (GCBench) compiled to native code, java runtime and bdwgc. |
Note: I've tried to produce a minimal statically-linked executable w/o proposed patch: See the experiment results in #722 |
Somewhat related issue: #568 |
Ah, cool, thank you! Will look into NOSYS when I get around to it. |
Right now in TinyGo (with this patch included), I've got a binary of 39kB on linux/arm64:
This is a small and (overly) simple test to see whether the GC is working at all and not overwriting memory. |
To be clear, the goal of this patch is to avoid linking in the vsnprintf function which is rather large. TinyGo binaries do not normally call printf-like functions, Go has its own formatting code. The code size savings of bdwgc itself are small in comparson. Before:
After:
(The output is a bit weird and designed for MCU usage, "flash" basically means binary size and "ram" means static data like non-constant globals). The bdwgc library goes from 24727 to 24199 bytes, a difference of half a kilobyte. That's not very large. However, the musl libc (which is statically linked) goes from 15725 to 4507 - around 10kB reduction. And not everything is accounted for: WebAssembly will be different, but since we also use a statically linked binary on WebAssembly, I expect a similar binary size reduction. (I also see that compiler-rt is ~3kB with vsnprintf linked in, that's all due to 128-bit float support and won't apply to WebAssembly). |
Got it, now it is more clear. |
This is mostly useful in environments where printf adds a non-negligible amount of code (for example, WebAssembly in the browser). Disabling all output shrinks the binary. Of course, this option should not be used when testing/debugging the GC.
I didn't test the binary size difference on WebAssembly, but on Linux (arm64) with a statically linked musl libc the difference is 20kB in my setup.