This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
pathom performance is affected by the number of resolvers. The same relatively simple query take 29ms when I have only 42 resolvers and almost 500ms when I have 204 (the added resolvers having no use for the query).
confirmed with a simple test:
(defn test-run [num]
(p.eql/process
(p.connect.indexes/register
(mapv (fn [i]
(p.connect.op/resolver
{::p.connect.op/op-name (symbol (str "a-" i))
::p.connect.op/output [(keyword (str "a-" i))]
::p.connect.op/resolve (fn [env p] {(keyword (str "a-" i)) i})}))
(range num)))
[:a-0]))
(time (test-run 10))
"Elapsed time: 1.045292 msecs"
=> {:a-0 0}
(time (test-run 100))
"Elapsed time: 5.460701 msecs"
=> {:a-0 0}
(time (test-run 1000))
"Elapsed time: 52.030815 msecs"
=> {:a-0 0}
(time (test-run 10000))
"Elapsed time: 509.117789 msecs"
=> {:a-0 0}
I think you should first build your index outside of the test and then process the query.
the pathom env is usually a singleton, built at system startup
yeah the perf issue is a bit trickier than that, I think there's a correlation between the number of links in the graph and the time it takes to respond to queries, it also manifests itself more for more complex queries where some requested attributes are obtains with an indirect path
aha duh thanks Thomas :D
(defn make-env [num]
(p.connect.indexes/register
(mapv (fn [i]
(p.connect.op/resolver
{::p.connect.op/op-name (symbol (str "a-" i))
::p.connect.op/output [(keyword (str "a-" i))]
::p.connect.op/resolve (fn [env p] {(keyword (str "a-" i)) i})}))
(range num))))
(let [env (make-env 10000)]
(time (p.eql/process env [:a-0])))
"Elapsed time: 4.714412 msecs"
=> {:a-0 0}
but if you do resolvers that produce the same output
brian.server-components.pathom> (let [env (make-env 10000)]
(time (p.eql/process env [:a])))
"Elapsed time: 40472.280115 msecs"
{:a 5842}
brian.server-components.pathom> (let [env (make-env 1000)]
(time (p.eql/process env [:a])))
"Elapsed time: 439.410852 msecs"
{:a 311}
brian.server-components.pathom> (let [env (make-env 100)]
(time (p.eql/process env [:a])))
"Elapsed time: 14.28388 msecs"
{:a 56}
brian.server-components.pathom> (let [env (make-env 10)]
(time (p.eql/process env [:a])))
"Elapsed time: 4.451542 msecs"
{:a 1}
(defn make-env [num]
(pci/register
(mapv (fn [i]
(pco/resolver
{::pco/op-name (symbol (str "a-" i))
::pco/output [(keyword (str "a"))]
::pco/resolve (fn [env p] {(keyword (str "a")) i})}))
(range num))))