[bazel] Enable dead code stripping on macOS #537
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the
-dead_strip
flag to the linker options on macOS when optimization is enabled, effectively replicating bazel's approach on Linux where--ffunction-sections
--gc-sections
flags are enabled by default under theopt
configuration.Based on the Mach-O binary format no compiler flag changes are needed, dead code stripping is linker-only.
optimized workerd binary size:
67.9MB -> 60.2MB
Up for discussion: I wasn't planning to enable this for fastbuild mode and only modified the .bazelrc file to show that the change won't break test cases, but based on local testing it might be a tiny bit faster since the linker generates and writes binaries with much fewer symbols. For
crypto-impl-asymmetric-test
, linking takes 1.5s instead of 1.8s and fastbuild binary size is down from 172MB to 116MB. While these results may not be representative – I expected dead_strip builds to be slower – this may reduce CI disk usage and improve the local build experience.