shorn: your Valibot schema already describes the payload, so why send the keys? #1590
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 Valibot schema you already have as a binary wire format. Both sides have the schema, 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. The wire codec right now is 5.1 KB gzip
Playground: https://shorn.dev
One question, since you can see it in the code above: is
toStandardJsonSchemathe right seam, or a wart I should remove? Zod and ArkType expose their JSON Schema directly, so Valibot is the one path where you pass a third argument to every call. I could detect it and do the conversion myself, but that pulls@valibot/to-json-schemainto everyone's bundle, which seemed like the wrong trade for a library that counts bytes.All reactions