Skip to content

feat(build): add hole-punch tool to reduce compressed binary size#245

Merged
BYK merged 5 commits intomainfrom
feat/hole-punch-binary
Feb 16, 2026
Merged

feat(build): add hole-punch tool to reduce compressed binary size#245
BYK merged 5 commits intomainfrom
feat/hole-punch-binary

Conversation

@BYK
Copy link
Member

@BYK BYK commented Feb 16, 2026

Summary

  • Adds script/hole-punch.ts — a post-compile tool that zeros unused ICU data entries inside Bun-compiled binaries, making zeroed regions compress to nearly nothing
  • Reduces gzip download size by ~24% (37 MB -> 28 MB) across all platforms
  • Runs automatically in CI after build, before smoke test

How 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 testing
  • test/lib/hole-punch.test.ts — 22 unit tests with synthetic ICU blob builder
  • .github/workflows/ci.yml — added hole-punch step after build
  • package.json — added hole-punch script

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.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 16, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Build

  • Add hole-punch tool to reduce compressed binary size by BYK in #245
  • Add gzip-compressed binary downloads by BYK in #244

Bug Fixes 🐛

  • (upgrade) Remove v prefix from release URLs and work around Bun.write streaming bug by BYK in #243

Internal Changes 🔧

  • Use @sentry/api client for requests by MathurAditya724 in #226

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 16, 2026

Codecov Results 📊

✅ Patch coverage is 80.43%. Project has 4181 uncovered lines.
✅ Project coverage is 68.44%. Comparing base (base) to head (head).

Files with missing lines (72)
File Patch % Lines
human.ts 58.29% ⚠️ 395 Missing
resolve-target.ts 20.26% ⚠️ 366 Missing
list.ts 14.39% ⚠️ 345 Missing
api-client.ts 59.38% ⚠️ 262 Missing
list.ts 23.47% ⚠️ 212 Missing
oauth.ts 30.68% ⚠️ 183 Missing
list.ts 21.96% ⚠️ 167 Missing
plan.ts 19.37% ⚠️ 154 Missing
resolver.ts 3.23% ⚠️ 120 Missing
help.ts 19.85% ⚠️ 109 Missing
upgrade.ts 61.37% ⚠️ 107 Missing
view.ts 36.48% ⚠️ 101 Missing
interactive-login.ts 9.17% ⚠️ 99 Missing
errors.ts 5.94% ⚠️ 95 Missing
view.ts 25.81% ⚠️ 92 Missing
view.ts 39.44% ⚠️ 86 Missing
clipboard.ts 4.49% ⚠️ 85 Missing
status.ts 24.07% ⚠️ 82 Missing
migration.ts 47.44% ⚠️ 82 Missing
list.ts 27.18% ⚠️ 75 Missing
browser.ts 4.11% ⚠️ 70 Missing
login.ts 33.33% ⚠️ 64 Missing
span-tree.ts 5.00% ⚠️ 57 Missing
explain.ts 33.33% ⚠️ 56 Missing
hole-punch.ts 80.43% ⚠️ 55 Missing
api.ts 89.80% ⚠️ 47 Missing
upgrade.ts 66.91% ⚠️ 46 Missing
telemetry.ts 84.72% ⚠️ 46 Missing
seer.ts 75.54% ⚠️ 45 Missing
schema.ts 89.56% ⚠️ 40 Missing
refresh.ts 40.63% ⚠️ 38 Missing
seer.ts 79.87% ⚠️ 30 Missing
preload.ts 53.23% ⚠️ 29 Missing
view.ts 87.27% ⚠️ 28 Missing
utils.ts 88.94% ⚠️ 25 Missing
view.ts 61.54% ⚠️ 25 Missing
detector.ts 90.10% ⚠️ 20 Missing
binary.ts 88.67% ⚠️ 17 Missing
list.ts 91.16% ⚠️ 16 Missing
list.ts 90.70% ⚠️ 16 Missing
code-scanner.ts 95.00% ⚠️ 16 Missing
help.ts 57.14% ⚠️ 15 Missing
sentry-client.ts 92.22% ⚠️ 13 Missing
arg-parsing.ts 90.00% ⚠️ 12 Missing
dsn-cache.ts 94.62% ⚠️ 12 Missing
logout.ts 56.00% ⚠️ 11 Missing
token.ts 52.17% ⚠️ 11 Missing
fix.ts 83.61% ⚠️ 10 Missing
qrcode.ts 33.33% ⚠️ 10 Missing
fs-utils.ts 57.14% ⚠️ 9 Missing
view.ts 94.70% ⚠️ 7 Missing
project-root.ts 97.73% ⚠️ 7 Missing
version-check.ts 91.76% ⚠️ 7 Missing
feedback.ts 84.21% ⚠️ 6 Missing
auth.ts 95.52% ⚠️ 6 Missing
shell.ts 96.23% ⚠️ 6 Missing
app.ts 93.90% ⚠️ 5 Missing
region.ts 86.49% ⚠️ 5 Missing
setup.ts 97.84% ⚠️ 4 Missing
list.ts 97.33% ⚠️ 4 Missing
index.ts 95.96% ⚠️ 4 Missing
project-aliases.ts 97.40% ⚠️ 2 Missing
project-root-cache.ts 96.92% ⚠️ 2 Missing
output.ts 89.47% ⚠️ 2 Missing
alias.ts 99.42% ⚠️ 1 Missing
completions.ts 99.37% ⚠️ 1 Missing
env-file.ts 99.19% ⚠️ 1 Missing
parser.ts 98.63% ⚠️ 1 Missing
colors.ts 98.21% ⚠️ 1 Missing
trace.ts 99.16% ⚠️ 1 Missing
helpers.ts 97.62% ⚠️ 1 Missing
helpers.ts 94.74% ⚠️ 1 Missing
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

@BYK BYK marked this pull request as ready for review February 16, 2026 13:08
- 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.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'.
@BYK BYK merged commit 02d192f into main Feb 16, 2026
23 checks passed
@BYK BYK deleted the feat/hole-punch-binary branch February 16, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant