From 932cd34c3425bc52c52a4a3b003ee0a894ae66b2 Mon Sep 17 00:00:00 2001 From: vemv Date: Fri, 9 Jul 2021 01:38:22 +0200 Subject: [PATCH] Parallelize `referred-syms-by-file&fullname` Part of https://github.com/clojure-emacs/refactor-nrepl/issues/230 --- CHANGELOG.md | 2 ++ src/refactor_nrepl/core.clj | 23 +++++++++++++++-------- src/refactor_nrepl/ns/libspecs.clj | 4 ++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c0de116..1b613941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/refactor_nrepl/core.clj b/src/refactor_nrepl/core.clj index 7976f878..5e899824 100644 --- a/src/refactor_nrepl/core.clj +++ b/src/refactor_nrepl/core.clj @@ -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] @@ -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) diff --git a/src/refactor_nrepl/ns/libspecs.clj b/src/refactor_nrepl/ns/libspecs.clj index 68568ce4..88f3121f 100644 --- a/src/refactor_nrepl/ns/libspecs.clj +++ b/src/refactor_nrepl/ns/libspecs.clj @@ -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)}))