Repository navigation
shorn: your ArkType type already describes the payload, so why send the keys? #1648
ChiChuRita
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 built shorn. It uses the ArkType type you already have as a binary wire format. Both sides have the type, so field names never go in the payload.
It's also faster. JSON has to write every key and parse it back out again. shorn skips that work entirely, so it's up to 6.2x faster to encode and 14.5x to decode in my benchmarks. The saving comes from the schema, not from compression, so there's no CPU cost to pay for it.
No IDL, no codegen, no second schema. It reads validation through Standard Schema and structure through Standard JSON Schema. ArkType types work directly, no adapter.
Playground: https://shorn.dev
One thing you might find interesting, since ArkType compiles too. I generate separate code for every schema instead of sharing one helper function. The reason is that V8 optimises a function based on the shapes it has seen at that spot in the code. Share one helper across a dozen schemas and it sees a dozen different shapes, gives up, and falls back to slow generic code. When I tried the shared version it came out about 3x slower than the plain loop I started with. Have you run into the same thing with compiled validators?
All reactions