Skip to content

Commit 6245a9e

Browse files
vemvbbatsov
authored andcommitted
Optimize analyze-stacktrace
1 parent 183c94b commit 6245a9e

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
* Make `middleware.stacktrace` detect a given project's common ns prefix even in face of single-segment namespaces such as `user`.
1212

13+
### Changes
14+
15+
* Parallelize `cider.nrepl.middleware.stacktrace/analyze-stacktrace`.
16+
1317
## 0.26.0 (2021-04-22)
1418

1519
### New features

src/cider/nrepl/middleware/stacktrace.clj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@
183183
"Flag the frame if it is from the users project. From a users
184184
project means that the namespace is one we have identified or it
185185
begins with the identified common prefix."
186-
[{:keys [ns] :as frame}]
186+
[namespaces {:keys [ns] :as frame}]
187187
(if (and ns
188-
(or (contains? (directory-namespaces) (symbol ns))
188+
(or (contains? namespaces (symbol ns))
189189
(when (:valid @ns-common-prefix)
190190
(.startsWith ^String ns (:common @ns-common-prefix)))))
191191
(flag-frame frame :project)
@@ -206,15 +206,18 @@
206206

207207
(defn analyze-frame
208208
"Return the stacktrace as a sequence of maps, each describing a stack frame."
209-
[frame]
210-
((comp flag-repl flag-project analyze-fn analyze-file stack-frame) frame))
209+
[namespaces frame]
210+
(let [f (comp flag-repl (partial flag-project namespaces) analyze-fn analyze-file stack-frame)]
211+
(f frame)))
211212

212213
(defn analyze-stacktrace
213214
"Return the stacktrace as a sequence of maps, each describing a stack frame."
214215
[^Exception e]
215-
(-> (map analyze-frame (.getStackTrace e))
216-
(flag-duplicates)
217-
(flag-tooling)))
216+
(let [namespaces (directory-namespaces)]
217+
(-> (pmap (partial analyze-frame namespaces)
218+
(.getStackTrace e))
219+
(flag-duplicates)
220+
(flag-tooling))))
218221

219222
;;; ## Causes
220223

src/cider/nrepl/middleware/test.clj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@
5757
(defn stack-frame
5858
"Search the stacktrace of exception `e` for the function `f` and return info
5959
describing the stack frame, including var, class, and line."
60-
[^Exception e f]
61-
(->> (map st/analyze-frame (.getStackTrace e))
62-
(filter #(= (:class %) (.getName (class f))))
63-
(first)))
60+
([^Exception e f]
61+
(stack-frame (st/directory-namespaces) e f))
62+
([namespaces ^Exception e f]
63+
(->> (map (partial st/analyze-frame namespaces) (.getStackTrace e))
64+
(filter #(= (:class %) (.getName (class f))))
65+
(first))))
6466

6567
(defn- print-object
6668
"Print `object` using pprint or a custom print-method, if available."
@@ -184,9 +186,10 @@
184186
finds the erring test fixture in the stacktrace and binds it as the current
185187
test var. Test count is decremented to indicate that no tests were run."
186188
[ns e]
187-
(let [frame (->> (concat (:clojure.test/once-fixtures (meta ns))
189+
(let [namespaces (st/directory-namespaces)
190+
frame (->> (concat (:clojure.test/once-fixtures (meta ns))
188191
(:clojure.test/each-fixtures (meta ns)))
189-
(map (partial stack-frame e))
192+
(map (partial stack-frame namespaces e))
190193
(filter identity)
191194
(first))
192195
fixture (resolve (symbol (:var frame)))]

0 commit comments

Comments
 (0)