Fork me on GitHub
#reitit
<
2019-01-22
>
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

Like:

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

ikitommi07:01:46

@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.

juhoteperi07:01:54

Building those 2 node vectors does have some cost

juhoteperi07:01:21

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

juhoteperi07:01:59

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

juhoteperi07:01:37

... 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)
      ,,,}))

juhoteperi08:01:47

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.

juhoteperi08:01:45

compile-request-coercers already does something similar

👍 5
koura11:01:43

is the example at :https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj outdated? When I browse to the swagger-ui I get the following msg: fetching resource list: undefined; Please wait.

koura12:01:20

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

ikitommi15:01:35

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

koura08:01:14

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

ikitommi16:01:16

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"

ikitommi17:01:24

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