Skip to content

SDK Bundle Size Regression Guard #586

Description

@Kingsman-99

Description

As the SDK grows, accidental imports of heavy polyfills or unused Stellar SDK sub-modules can silently inflate the distributed bundle, harming browser-based dApp consumers who pay the cost at page load time. There is currently no CI enforcement of bundle size, meaning regressions are only discovered after reaching consumers. A size regression guard would measure the minified and gzipped ESM bundle on every pull request and fail the build if the size exceeds a threshold or grows by more than an allowed percentage relative to the main-branch baseline.

Technical Context

New script scripts/bundle-size-guard.ts executed via tsx. Uses esbuild (already a dev dependency) to produce a one-shot ESM bundle from src/index.ts, then zlib.gzip to measure compressed size. Baseline recorded in scripts/bundle-size-baseline.json. A new bundle:check npm script added to package.json. A companion bundle:update-baseline script regenerates the baseline file. Thresholds defined in scripts/bundle-size-config.ts.

Acceptance Criteria

  • npm run bundle:check exits with code 0 when the bundle is within threshold and code 1 when it exceeds it, printing a human-readable size comparison
  • The guard reports minified size, gzipped size, absolute delta, and percentage change from baseline, all written to bundle-size-report.json
  • Changes smaller than a configurable minimum noise floor (default 1 KB gzipped) are ignored to prevent spurious CI failures on trivial edits
  • npm run bundle:update-baseline overwrites bundle-size-baseline.json with current measurements; the script is guarded against accidental invocation outside CI by checking a BUNDLE_BASELINE_UPDATE=true env var
  • Tests assert that the guard exits with the correct code for a bundle under threshold, exactly at threshold, and over threshold
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions