Run path-conflicting just once for quarantine router

This commit is contained in:
Tommi Reiman 2020-04-26 22:04:14 +03:00
parent 0d3a195cd8
commit b128a0f3db
2 changed files with 17 additions and 4 deletions

View file

@ -301,7 +301,7 @@
([compiled-routes]
(quarantine-router compiled-routes {}))
([compiled-routes opts]
(let [conflicting-paths (-> compiled-routes (impl/path-conflicting-routes opts) impl/conflicting-paths)
(let [conflicting-paths (impl/conflicting-paths (or (::path-conflicting opts) (impl/path-conflicting-routes compiled-routes opts)))
conflicting? #(contains? conflicting-paths (first %))
{conflicting true, non-conflicting false} (group-by conflicting? compiled-routes)
linear-router (linear-router conflicting opts)
@ -389,7 +389,7 @@
(when-let [validate (:validate opts)]
(validate compiled-routes opts))
(router compiled-routes opts))
(router compiled-routes (assoc opts ::path-conflicting path-conflicting)))
(catch #?(:clj Exception, :cljs js/Error) e
(throw ((get opts :exception identity) e)))))))

View file

@ -1,5 +1,5 @@
(ns reitit.router-creation-perf-test
(:require [reitit.perf-utils :refer [bench!]]
(:require [reitit.perf-utils :refer [bench! suite]]
[reitit.core :as r]
[clojure.string :as str])
(:import (java.util Random)))
@ -32,12 +32,25 @@
(let [rnd (random 1)]
(mapv (fn [n] [(route rnd) (keyword (str "route" n))]) (range 100))))
(conj hundred-routes (last hundred-routes))
(defn bench-routers []
(suite "non-conflicting")
;; 104ms
(bench! "default" (r/router hundred-routes))
;; 7ms
(bench! "linear" (r/router hundred-routes {:router r/linear-router, :conflicts nil})))
(bench! "linear" (r/router hundred-routes {:router r/linear-router, :conflicts nil}))
(suite "conflicting")
(let [routes (conj hundred-routes [(first (last hundred-routes)) ::route])]
;; 205ms
;; 105ms (cache path-conflicts)
(bench! "default" (r/router routes {:conflicts nil}))))
(comment
(bench-routers))