reitit

flowthing 2025-09-23T10:27:59.049559Z

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)?

opqdonut 2025-09-25T09:53:19.125749Z

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.

opqdonut 2025-09-25T10:12:59.693159Z

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)))

flowthing 2025-09-25T10:13:53.096239Z

Many thanks! Yeah, I got as far as default-parameter-coercion, but found it difficult to figure out how to pass it.

opqdonut 2025-09-25T10:14:47.459959Z

yeah this is definitely a very-seldom-trod corner of reitit/malli

opqdonut 2025-09-25T10:14:54.299889Z

I'm curious: what's your use case?

flowthing 2025-09-25T10:14:58.921619Z

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.

opqdonut 2025-09-25T10:15:12.016849Z

right, that tracks

flowthing 2025-09-25T10:15:16.489029Z

Keywordizing keys via reitit.walk/keywordize-keys specifically, that is.

opqdonut 2025-09-25T10:15:28.833709Z

I've run into the same hotspot in the past (pre-reitit)

👍 1
opqdonut 2025-09-25T10:17:18.395809Z

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

flowthing 2025-09-25T10:19:00.550949Z

Yeah, that makes sense. Will look into that, thanks. 👍

Ben Sless 2025-09-30T07:05:36.264379Z

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

flowthing 2025-09-30T08:17:41.982769Z

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.

flowthing 2025-09-30T08:18:41.176689Z

Not much sense in keywordizing headers, for example, just to throw out the end results.

Ben Sless 2025-09-30T08:25:07.753519Z

absolutely. could be worth exposing an API for users who want to control which parts get keyordized 🤔

flowthing 2025-09-30T08:29:15.226209Z

That's what @joel.kaasinen's example above is for, no? Wouldn't hurt to have it documented better, though, I think.

opqdonut 2025-09-30T08:30:40.629149Z

yeah it's definitely not discoverable right now!