clojure-spec

vemv 2023-09-21T09:03:12.665509Z

(One of those "just curious" questions 🙂) Is there an intrinsic reason why spec (1) is slower than Malli? It's relatively common to hear that it's not performant enough to be used in something like a web handler. However it doesn't sound too crazy to implement some sort of drop-in replacement for a few key functions like conform. One would still use the regular spec/def for definitions - the custom checker could simply read the original registry.

nikolavojicic 2023-09-21T10:43:52.198519Z

Never had a significantly slow spec such that it matters for web app... For data generation yes, it can be slow and can be fixed by tweaking generators. Is there an example?

vemv 2023-09-21T11:38:53.182269Z

'That matters' is the tricky part... for many webapps a 1ms delay doesn't appear to matter, but if you are trying to serve thousands of requests per second, it becomes the bottleneck

seancorfield 2023-09-21T15:12:43.462319Z

We use conform heavily in our main REST API at work and it's "fast enough". I guess if you have an app where Spec's performance matters and Malli satisfies while Spec does not, then use Malli? We've never seen Spec as a bottleneck. JDBC stuff, yes. Elastic Search stuff, yes. Spec, never.

vemv 2023-09-21T15:21:24.716079Z

I once participated in a project where we used, roughly speaking, spec for code (fdefs and the like), and malli for data. Wasn't bad, I might even enjoy exercising all those skills on a good day, but it doesn't seem ideal. I'm a spec1 fan and would rather use it everywhere... but its performance is theoretically inferior. Again, you can say the same about e.g. Rails or Python web servers. In reality CPU is rarely the bottleneck, as you hint... but some of us enjoy squeezing the last drop of performance. Knowing it can do fast coercion, validation, etc can help in the occasional team-wide decision making processes.

vemv 2023-09-21T15:24:58.163419Z

Reflecting a bit, a later project used Malli in a more advanced way. I had the impression that you could go as far as building "your own spec1" but in Malli terms. Would seem a clearer path than hacking on spec1, as it is a stalled project.

2023-09-23T22:33:56.742219Z

w.r.t conform vs decode/encode in malli a lot more optimization work is done at 'compile time' (in the sense of constructing a chain of lambda functions to arrive at a a parser) e.g. in malli , it's possible your decoder/conform compiles to an identity function

2023-09-23T22:34:47.441459Z

💯 1
2023-09-23T22:36:55.219059Z

This is partly due to different designs, because the construction of the decoder/parser takes into account the structure of the input, if you know you're only trying to create morphisms between JSON <-> EDN , you can optimize more

2023-09-23T22:38:53.145059Z

Personally, i'm a huge fan of malli, i think its closer to rich hickey's definition of simplicity than spec version 1, since specs/schema are just data, ... this could change with spec version 2, but i'm a convert for now.