How much work does defining a type do at runtime?
eg, is it likely to be a performance issue to call
type('string.json.parse').pipe(MyPayload)(body) on every message we want to parse vs saving the functoin somewhere, or is it pretty lightweight? (Yeah, I can benchmark 🙂 but wondering if there's a recommendation.)2 Replies
yeah initialization is very expensive compared to validation I would do whatever you can to define the types at the top-level of the module so it only occurs once
string definitions are cached during parsing so there's some savings there but especially if you're parsing an object definition there's a lot involved in the reduction => JIT optimization steps to make the validation really fast, so definitely want to avoid incuring that O(n) times
thanks!