Fork me on GitHub
Vincent Cantin06:01:56

I noticed the function reitit.coercion/coerce-request and wonder if it would be more performant to use into with a transducer instead of reduce-kv. Did someone already tried?

Vincent Cantin06:01:28


(defn coerce-request [coercers request]
  (into {}
        (fn [k coercer]
          [k (coercer request)])


@vincent.cantin good catch. I don't think anyone has tried that.

Vincent Cantin07:01:28

into is creating a mutable write-only collection in which writing is faster because no new collection is created at each write, then turns it into an immutable at the end of the transducing process.

Vincent Cantin07:01:53

In theory (some tests are needed though), it could be faster.


Building those 2 node vectors does have some cost


One option is to use transient maps with reduce-kv, but they aren't faster always either


For Clojure JVM, using MapEntry instead of vector might be faster, if using transducer: (clojure.lang.MapEntry. k ...)


... though it is recommended that the class is not used directly

Vincent Cantin07:01:48

Another option (which I am not sure would make sense as I did not finish to read the full documentation) would be to macro-expand the coercers into a pre-compiled literal Clojure map.

Vincent Cantin07:01:10

Something like:

(defn request-coercer [coercers]
  `(fn coerce-request [request]
     {:key1 (~(:key1 coercers) request)
      :key2 (~(:key2 coercers) request)


Coercers are set in runtime so macro expansion doesn't work. But it could be possible to "precompile" coercers into coerce-request function as some stage.


compile-request-coercers already does something similar

👍 5

is the example at : outdated? When I browse to the swagger-ui I get the following msg: fetching resource list: undefined; Please wait.


got it working now, I had a dependency that was apparently conflicting with something


@UDCB49XK3 could you fix the dependencies if they are out-of-sync?


the out of sync dependencies were in my own side. Not the fault of the example


One more stab at fast trie-based routing: I have a working draft of a fast radix-trie, about the same perf as the current segment-trie, but is not tied to segments. Would allow bracket-parameters like "/api/docs/{folder}/{file}.pdf"


Also, qualified keys & any path delimeter: "messages.{my/broker}.{my/topic}"