dunx: NestJS-style DI on Bun, and what the layer costs #42769
petarzarkov
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I wanted NestJS's structure without the 244ms boot or reflect-metadata, so I built dunx on
Bun.serve.Constructor injection, no parameter decorators, no reflect-metadata, no
experimentalDecorators. An oxc transform reads the constructor's parameter types at load time and records them under a symbol, so the declaration is just the class:A parameter whose type is erased (an interface, a primitive, a type-only import) is a boot error naming that parameter, rather than a silent
undefinedat the first call.Routing is
Bun.serve({ routes }). I did not write a router, so path params, per-method dispatch and method-miss 404s are Bun's.Since
@dunx/httpis a layer over that exact API, the gap to rawBun.serveis framework overhead and nothing else:Bun.serverawRyzen 9 5950X, Bun 1.4.2, oha at 64 connections, 5s, median of 5 runs. The load generator shares the box with the subject, so read it as a ranking and not as capacity. axum is ahead on the db scenario and that gap is real.
The number I would want if I were reading this: turn structured logging on and dunx drops to 81k plaintext, 60% of raw
Bun.serve. Per-request logging costs more than the framework does. That is true of every subject in the suite, it just usually is not the number anyone publishes.Harness and raw JSON: https://github.com/petarzarkov/dunx/tree/main/internal/bench
Repo: https://github.com/petarzarkov/dunx
All reactions