Skip to content

Commit ba5382b

Browse files
authored
Parallelize referred-syms-by-file&fullname (#320)
Part of #230
1 parent c05e692 commit ba5382b

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## Unreleased
44

55
#### Changes
6+
7+
* [(Part of #230)](https://github.com/clojure-emacs/refactor-nrepl/issues/230): Parallelize various functionality
8+
* This will have a noticeable improvement in e.g. clj-refactor.el's `cljr-slash` performance.
69
* [#291](https://github.com/clojure-emacs/refactor-nrepl/issues/291): The `:ignore-errors` option will be honored in more places, making refactor-nrepl more robust in face of files not particularly meant to be part of the AST corpus.
710
* Examples: WIP files, Moustache template files, scripts.
811
* Upgrade Orchard
@@ -15,6 +18,7 @@
1518
* Honor internal `future-cancel` calls, improving overall responsiveness and stability.
1619

1720
### Bugs fixed
21+
1822
* [#289](https://github.com/clojure-emacs/refactor-nrepl/issues/289): Fix an edge-case with involving keywords that caused find-symbol to crash.
1923
* [#305](https://github.com/clojure-emacs/refactor-nrepl/issues/305): Don't put `:as` or `:refer` on their own lines in the ns form, when the libspec is so long it causes the line to wrap.
2024
* [clojure-emacs/clj-refactor.el#459](https://github.com/clojure-emacs/clj-refactor.el/issues/459): `clean-ns` should conform to the style guide: `(:require` in the ns form should be followed by a newline.

src/refactor_nrepl/core.clj

+16-8
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,20 @@
9999
(defn find-in-dir
100100
"Searches recursively under dir for files matching (pred ^File file).
101101
102-
Note that files which are non-existant, hidden or build-artifacts
102+
Note that files which are non-existent, hidden or build-artifacts
103103
are pruned by this function."
104104
[pred dir]
105-
(->> dir
106-
file-seq
107-
(filter (every-pred fs/exists?
108-
(complement fs/hidden?)
109-
pred
110-
(complement build-artifact?)))))
105+
(->> dir
106+
file-seq
107+
;; `pmap` performs better in large projects.
108+
(pmap (fn [f]
109+
(when ((every-pred fs/exists?
110+
(complement fs/hidden?)
111+
pred
112+
(complement build-artifact?))
113+
f)
114+
f)))
115+
(filter identity)))
111116

112117
(defn read-ns-form
113118
([path]
@@ -184,7 +189,10 @@
184189
(defn find-in-project
185190
"Return the files in the project satisfying (pred ^File file)."
186191
[pred]
187-
(-> find-in-dir (partial pred) (mapcat (dirs-on-classpath)) distinct))
192+
(->> (dirs-on-classpath)
193+
(pmap (partial find-in-dir pred))
194+
(apply concat)
195+
distinct))
188196

189197
(defn throw-unless-clj-file [file-path]
190198
(when-not (re-matches #".+\.clj$" file-path)

src/refactor_nrepl/ns/libspecs.clj

+4-3
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,22 @@
7777

7878
(defn referred-syms-by-file&fullname
7979
"Return a map of filename to a map of sym fullname to sym
80-
the sym itself
80+
the sym itself.
8181
8282
Example:
8383
{:clj {\"/home/someuser/projects/some.clj\" [\"example.com/foobar\" foobar]}
8484
:cljs}"
8585
([]
8686
(referred-syms-by-file&fullname false))
8787
([ignore-errors?]
88+
;; `pmap` is used as it has proved to be more efficient, both for cached and non-cached cases.
8889
{:clj (->> (core/find-in-project (util/with-suppressed-errors
8990
(some-fn core/clj-file? core/cljc-file?)
9091
ignore-errors?))
91-
(map (juxt identity (partial get-libspec-from-file-with-caching :clj)))
92+
(pmap (juxt identity (partial get-libspec-from-file-with-caching :clj)))
9293
sym-by-file&fullname)
9394
:cljs (->> (core/find-in-project (util/with-suppressed-errors
9495
(some-fn core/cljs-file? core/cljc-file?)
9596
ignore-errors?))
96-
(map (juxt identity (partial get-libspec-from-file-with-caching :cljs)))
97+
(pmap (juxt identity (partial get-libspec-from-file-with-caching :cljs)))
9798
sym-by-file&fullname)}))

0 commit comments

Comments
 (0)