How do I tell Malli not to keywordize keys (i.e. make keywordize? here https://github.com/metosin/reitit/blob/7520d20f123c801d5f8bf9689301ccadd1dae4a5/modules/reitit-core/src/reitit/coercion.cljc#L96 false)?
excellent question! you should wire in your own replacement for default-parameter-coercion, but it's not obvious how to do that. I'll dig around.
here's how I managed to do it in the reitit ring-example:
(def app
(ring/ring-handler
(ring/router
[example.plain/routes
example.schema/routes
example.dspec/routes
example.spec/routes]
{:data {:muuntaja m/instance
:middleware [params/wrap-params
muuntaja/format-middleware
coercion/coerce-exceptions-middleware
coercion/coerce-request-middleware
coercion/coerce-response-middleware]}
:reitit.coercion/parameter-coercion (assoc-in reitit.coercion/default-parameter-coercion
[:query :keywordize?]
false)})
(ring/create-default-handler)))Many thanks! Yeah, I got as far as default-parameter-coercion, but found it difficult to figure out how to pass it.
yeah this is definitely a very-seldom-trod corner of reitit/malli
I'm curious: what's your use case?
I profiled one of our apps and it seems like it's spending most of its CPU time keywordizing keys, which does not seem very useful, so I figured I'd check what happens if I disable it.
right, that tracks
Keywordizing keys via reitit.walk/keywordize-keys specifically, that is.
I've run into the same hotspot in the past (pre-reitit)
for perf-sensitive stuff, you might want to skip coerce-request-middleware and just do the minimal coercion/validation you can in the handler, perhaps using malli functions directly
Yeah, that makes sense. Will look into that, thanks. 👍
Do you have some profiling results you can share? I'd be interested to see if I left any performance bugs lying on the floor there
I'm pretty sure there are no significant performance bugs. In this particular case, it's just that the app uses very little CPU in general -- so little, that key keywordization pops up in the JFR recording. Since the keywordization is unnecessary in this case (only one place in the code relies on it), the most sensible approach is to just not do it, I think.
Not much sense in keywordizing headers, for example, just to throw out the end results.
absolutely. could be worth exposing an API for users who want to control which parts get keyordized 🤔
That's what @joel.kaasinen's example above is for, no? Wouldn't hurt to have it documented better, though, I think.
yeah it's definitely not discoverable right now!