Fork me on GitHub
#pedestal
<
2023-08-18
>
simon08:08:50

Thanks a lot for your explanation, it all starts to click. 😊 I have also read through the live-repl guide, somehow I've missed it before, it has also really thorough explanations, very cool. You mention the cost of de-referencing - it's hard for me to estimate the impact of it, is it ok to run it like this in production? Asking because in the live-repl guide they say to not use a function to create the routes in production, but I guess the cost of de-referencing is ok?

phill10:08:32

If you operate Twitter then you might do well to avoid the extra dereference. The difference might be so small that web performance tools could not even measure it, but of course the more requests your server receives, the faster it adds up. Clojure is great for first-order, "work smarter, not harder" speed, relative to other tools where you have to program "safe copies" of things or derive map keys from objects by toString all the time. But, Clojure offers some second-order, elective, micro-inefficiencies, like lazy sequences. Rule of thumb: if you're OK with lazy sequences then you need not worry about the extra dereference. Creating routes with a function is fine too, but you do not want Pedestal to call that function every time it gets a request. In production, once is plenty (if we may assume the result will be equivalent every time). How bad is it? Well, what you see in your development environment is what you'll get. It might feel OK. Just don't do it. 🙂

simon12:08:54

Thank you! 😊 That sounds like good advice. About "work smarter, not harder", that was also my thinking. In the way I use clojure it is probably not optimized for speed, and I guess I could make many improvements, so the extra dereference wouldn't matter that much. Also thanks for the tip about the routes. In the end I've tried to :enter #'update-presence, but then an assert failed about it not being a valid interceptor anymore. So in the end I redefined the function calling the db in the interceptor, which was what I wanted to avoid. Thanks for sharing your knowledge! I keep being amazed by the support of the clojure community. 😊