-
Notifications
You must be signed in to change notification settings - Fork 521
Improve performance of params middleware #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Can I see the benchmarks? |
I'll rerun them and share the results here, both criterium and clj-async-profiler |
(ns user
(:require
[clojure.pprint :refer [pprint]]
[ring.util.io :refer [string-input-stream]]
[ring.middleware.params :refer [wrap-params]]
[criterium.core :as cc]
[clj-async-profiler.core :as prof]))
(def wrapped-echo (wrap-params identity))
(def reqs
[
{:query-string "foo=bar&biz=bat%25"}
{:query-string "foo=bar"
:headers {"content-type" "application/x-www-form-urlencoded"}
:body (string-input-stream "biz=bat%25")}
{:headers {"content-type" "application/json"}
:body (string-input-stream "{foo: \"bar\"}")}
{:query-string ""
:headers {"content-type" "application/x-www-form-urlencoded"}
:body (string-input-stream "")}
{:headers {"content-type" "application/x-www-form-urlencoded;charset=UTF-16"}
:body (string-input-stream "hello=world" "UTF-16")}
])
(comment
(doseq [req reqs]
(pprint req)
(cc/quick-bench (wrapped-echo req)))) Results
|
Thanks for the benchmarks. It looks like we can make some small improvements around the performance of these functions, but I'd like to do so in a way that doesn't adversely impact readability. Perhaps instead we start from a function like: (defn- assoc-param-map [req k v]
(some-> req (assoc k (if-let [v' (req k)]
(reduce-kv assoc v' v)
v)))) And then write something like: (-> request
(assoc-param-map :query-params params)
(assoc-param-map :params params)) |
How about something like this: (defn assoc-query-params
"Parse and assoc parameters from the query string with the request."
{:added "1.3"}
[request encoding]
(let [params (if-let [query-string (:query-string request)]
(parse-params query-string encoding)
{})]
(-> request
(assoc-param-map :query-params params)
(assoc-param-map :params params)))) Also, how about |
By the way, for reference, you can take a look at the flame graphs I generated here and see which parts of |
@weavejester Sorry for tagging you but I wouldn't want this to fall by the wayside. Anything else I can do or provide to help this along? |
That looks fine.
I'd prefer to keep it consistent with the naming of |
9e90830
to
e0350f1
Compare
@weavejester gentle reminder 🙂 |
e0350f1
to
a4397ff
Compare
Could you change the commit message to:
|
a4397ff
to
1147268
Compare
@weavejester done |
@weavejester Changed PR title as well to align with commit message. |
Hello :) Thanks |
Probably by the end of the year. This patch seems non-critical. |
Absolutely, just wanted to know so I could plan towards running the next batch of benchmarks, those experiments take long times to complete so I want to batch the updates to the libraries I'm using, too. |
Improve performance of assoc-query-params and assoc-form-params