ReviewOS

stacks/bun-router

perf(router): isolate the runtime initializer from root helpers

#900
Closed chris opened this 8 days ago ·
8 days ago

The new @stacksjs/bun-router/runtime entry exports only the serving surface, but it currently reaches Router through src/router/index.ts. That root barrel also imports fluent builders, validation integration, response macros, middleware-pipeline helpers, route caching, and subdomain routing exports that the runtime entry does not expose.

An exact Bun 1.4.2 single-entry build records 43 source inputs and 139,032 minified bytes. The unrelated root-only contributors include fluent-routing.ts, validation/validator.ts, response/macros.ts, route-caching.ts, subdomain-routing.ts, and middleware/pipeline.ts.

Acceptance criteria:

  • factor the complete Router extension registration and module augmentation into one shared initializer,
  • make both the root router barrel and runtime entry use that initializer,
  • preserve every registered Router method and the existing runtime response behavior,
  • keep root-only helper exports out of the runtime static graph with a regression test,
  • measure the emitted graph and fresh-process import cost on exact Bun 1.4.2,
  • include the result in the pending 0.1.19 release evidence without publishing until explicitly approved.
8 days ago

Implemented the runtime initializer split in 65e3919.

The runtime entry now imports the complete Router prototype initializer directly, while the package root adds fluent routing, validation, caching, middleware pipeline, response macro, and subdomain helpers. Root and runtime keep the same Router class and serving behavior.

Evidence on exact Bun 1.4.2:

  • Full suite: 1,007 pass, 0 fail, 3,053 assertions across 61 files.
  • Standard and registry declaration typechecks passed.
  • Pickier lint and the production package build passed.
  • The installed runtime graph fell from 157,974 bytes across 3 files to 114,700 bytes across 2 files, saving 43,274 bytes or 27.4%.
  • A clean exact-revision diagnostic with 30 alternating fresh-process pairs measured median import time at 13.989417 ms for the root and 6.8918125 ms for runtime, a 50.74% reduction. Runtime was lower in 29 of 30 pairs.
  • Median settled RSS was 22,069,248 bytes for the root and 18,907,136 bytes for runtime, saving 3,162,112 bytes or 14.33%. Runtime was lower in all 30 pairs.
  • A fresh tarball consumer passed root, runtime, container, generated declaration, and both CLI entry checks.

CI for the exact implementation revision is running at https://github.com/stacksjs/bun-router/actions/runs/35571128724. I will close this issue after that run is green and the release notes reference the implementation.

8 days ago

The exact implementation revision passed the full main CI workflow: https://github.com/stacksjs/bun-router/actions/runs/35571128724

The release notes now reference the optimization. The runtime initializer split, static graph guard, installed-package validation, and clean Bun 1.4.2 diagnostics are complete, so this issue is resolved.

Sign in to comment on this issue.