trpc icon indicating copy to clipboard operation
trpc copied to clipboard

feat: Move zod parsing on inputs and outputs to another thread to not block main thread

Open anonrose opened this issue 7 months ago โ€ข 3 comments

Describe the feature you'd like to request

With large request and response objects zod parsing on .input(Schema) and .output(Schema) take quite a while for our schema. Suggest moving the parsing to another thread to not block main thread.

Describe the solution you'd like to see

Move the safeParse to another thread

Describe alternate solutions

Not sure what an alternative would be but open to suggestions.

Additional information

No response

๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributing

  • [x] ๐Ÿ™‹โ€โ™‚๏ธ Yes, I'd be down to file a PR implementing this feature!

anonrose avatar Apr 21 '25 21:04 anonrose

This would be awesome; we are considering move off Zod because we often have to accept very large objects via our REST APIs and by default this blocks the main event loop.

sumanyu avatar Apr 21 '25 21:04 sumanyu

moving the parsing to another thread to not block main thread how can you implement it? Should be use 2-4 replicas of application to serve request efficiently?

BCsabaEngine avatar Apr 29 '25 19:04 BCsabaEngine

Would be interested to see a POC of this with some benchmarks. Intuitively I would assume any costs of transferring data to and from a worker would outsize any benefit to validation speed.

Maybe we could support async input/output parsers and that would allow moving work to a worker in userland fairly easily with a simple wrapper?

Nick-Lucas avatar Apr 29 '25 20:04 Nick-Lucas