feat(build): add hole-punch tool to reduce compressed binary size#245
Merged
feat(build): add hole-punch tool to reduce compressed binary size#245
Conversation
Post-compile tool that zeros unused ICU data entries inside Bun-compiled binaries. The zeroed regions compress to nearly nothing, reducing gzip download size by ~24% (37 MB -> 28 MB). The tool scans for the ICU data blob via magic bytes, parses the TOC, and zeros entries that are safe to remove: legacy charset converters, CJK dictionaries, and non-English locale data. Root-level entries, normalization files, and English locale data are preserved. Runs automatically in CI after build, before smoke test, on all targets.
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Build
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ Patch coverage is 80.43%. Project has 4181 uncovered lines. Files with missing lines (72)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 68.18% 68.44% +0.26%
==========================================
Files 108 109 +1
Lines 12968 13249 +281
Branches 0 0 —
==========================================
+ Hits 8842 9068 +226
- Misses 4126 4181 +55
- Partials 0 0 —Generated by Codecov Action |
- Fix last ICU entry overwrite: skip the last TOC entry during zeroing since its size is estimated (no successor to measure against) and could overwrite bytes outside the ICU blob boundary. - Integrate hole-punch into build.ts before the gzip step so compressed artifacts benefit from zeroed regions. Previously hole-punch ran as a separate CI step after gzip was already created. - Remove standalone hole-punch CI step (now handled inside build). - Export runCli, formatSize, estimateLastEntrySize for direct testing. - Add 20 new tests covering: runCli paths, formatSize, estimateLastEntrySize edge cases, processBinary, parseIcuToc error paths, safeSize bounds. - Line coverage: 65% -> 81%, function coverage: 73% -> 92%.
…uild
- Add missing 'import { processBinary }' in build.ts (would have caused
ReferenceError at runtime).
- Wrap parseIcuToc/holePunch in try-catch inside processBinary so an
unexpected ICU layout skips hole-punch gracefully instead of crashing
the build.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
writeFileSync errors now propagate instead of being silently swallowed as 'no ICU data found'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
script/hole-punch.ts— a post-compile tool that zeros unused ICU data entries inside Bun-compiled binaries, making zeroed regions compress to nearly nothingHow it works
The Bun runtime embeds a 29 MB ICU data blob for international locale support. Most entries (legacy charset converters, CJK dictionaries, non-English locale data) are unused by a CLI tool. The tool scans for the ICU blob via magic bytes, parses its TOC, and zeros safe-to-remove entries while preserving root-level data, normalization files, and English locale data that Bun accesses at startup/shutdown.
Changes
script/hole-punch.ts— hole-punch tool with modular exports for testingtest/lib/hole-punch.test.ts— 22 unit tests with synthetic ICU blob builder.github/workflows/ci.yml— added hole-punch step after buildpackage.json— addedhole-punchscript