Skip to content

Commit

Permalink
Parallelize referred-syms-by-file&fullname
Browse files Browse the repository at this point in the history
Part of #230
  • Loading branch information
vemv committed Jul 8, 2021
1 parent 67518a5 commit 932cd34
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,8 @@
## Unreleased

#### Changes
* [(Part of #230)](https://github.com/clojure-emacs/refactor-nrepl/issues/230) Parallelize various fuctionality
* This will have a noticeable improvement in e.g. clj-refactor.el's `cljr-slash` performance.
* [#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.
* Examples: WIP files, Moustache template files, scripts.
* Upgrade Orchard
Expand Down
23 changes: 15 additions & 8 deletions src/refactor_nrepl/core.clj
Expand Up @@ -99,15 +99,19 @@
(defn find-in-dir
"Searches recursively under dir for files matching (pred ^File file).
Note that files which are non-existant, hidden or build-artifacts
Note that files which are non-existent, hidden or build-artifacts
are pruned by this function."
[pred dir]
(->> dir
file-seq
(filter (every-pred fs/exists?
(complement fs/hidden?)
pred
(complement build-artifact?)))))
(->> dir
file-seq
(pmap (fn [f]
(when ((every-pred fs/exists?
(complement fs/hidden?)
pred
(complement build-artifact?))
f)
f)))
(filter identity)))

(defn read-ns-form
([path]
Expand Down Expand Up @@ -184,7 +188,10 @@
(defn find-in-project
"Return the files in the project satisfying (pred ^File file)."
[pred]
(-> find-in-dir (partial pred) (mapcat (dirs-on-classpath)) distinct))
(->> (dirs-on-classpath)
(pmap (partial find-in-dir pred))
(apply concat)
distinct))

(defn throw-unless-clj-file [file-path]
(when-not (re-matches #".+\.clj$" file-path)
Expand Down
4 changes: 2 additions & 2 deletions src/refactor_nrepl/ns/libspecs.clj
Expand Up @@ -88,10 +88,10 @@
{:clj (->> (core/find-in-project (util/with-suppressed-errors
(some-fn core/clj-file? core/cljc-file?)
ignore-errors?))
(map (juxt identity (partial get-libspec-from-file-with-caching :clj)))
(pmap (juxt identity (partial get-libspec-from-file-with-caching :clj)))
sym-by-file&fullname)
:cljs (->> (core/find-in-project (util/with-suppressed-errors
(some-fn core/cljs-file? core/cljc-file?)
ignore-errors?))
(map (juxt identity (partial get-libspec-from-file-with-caching :cljs)))
(pmap (juxt identity (partial get-libspec-from-file-with-caching :cljs)))
sym-by-file&fullname)}))

0 comments on commit 932cd34

Please sign in to comment.