Skip to content

Commit 9c32bfb

Browse files
alexander-yakushevbbatsov
authored andcommitted
Disable warmup of orchard.java caches
Also, warm up Compliment caches.
1 parent 5b6a48a commit 9c32bfb

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## master (unreleased)
44

5+
* [#913](https://github.com/clojure-emacs/cider-nrepl/pull/913): Disable background warmup of `orchard.java` cache.
6+
* [#913](https://github.com/clojure-emacs/cider-nrepl/pull/913): Enable background warmup of Compliment cache.
7+
58
## 0.52.1 (2025-02-24)
69

710
* Bump `orchard` to [0.30.1](https://github.com/clojure-emacs/orchard/blob/master/CHANGELOG.md#0301-2025-02-24).

src/cider/nrepl.clj

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[cider.nrepl.middleware :as mw]
1212
[cider.nrepl.middleware.util.cljs :as cljs]
1313
[cider.nrepl.print-method] ;; we load this namespace, so it's directly available to clients
14+
[compliment.core :as compliment]
1415
[haystack.analyzer :as analyzer]
1516
[nrepl.middleware :refer [set-descriptor!]]
1617
[nrepl.middleware.caught :refer [wrap-caught]]
@@ -51,29 +52,19 @@
5152
(catch Exception _))
5253
@analyzer/spec-abbrev
5354

54-
(defn warmup-orchard-caches!
55-
"Warms up `orchard.java/cache`, drastically improving the completion and info UX performance for first hits.
56-
(This was our behavior for many years,
57-
then had to be disabled for test suite reasons in Orchard 0.15.0 to 0.17.0 / cider-nrepl 0.38.0 to 0.41.0, and now it's restored again)
58-
Note that this can only be done cider-nrepl side, unlike before when it was done in Orchard itself."
55+
(defn warmup-caches!
56+
"Warm up some of the dependency caches to improve UX performance for first hits.
57+
The warmups should be non-invasive (avoid unpredictable side-effects like e.g.
58+
loading classes). Currently only warms up Compliment, others are TBD."
5959
[]
60-
;; Cache classes that are `:import`ed throughout the project. The class list
61-
;; is obtained through `ns` form analysis, so that we don't depend on whether
62-
;; the namespaces have been loaded yet:
63-
(doseq [ns-form (vals (orchard.namespace/project-ns-forms))
64-
class-sym (orchard.namespace/ns-form-imports ns-form)
65-
:when (try
66-
(Class/forName (str class-sym)
67-
false ;; Don't initialize this class, avoiding side-effects (including static class initializers; with the exception of static fields with an initial value)
68-
(.getContextClassLoader (Thread/currentThread)))
69-
(catch Throwable _))]
70-
(orchard.java/class-info class-sym))
71-
;; 3.- Leave an indicator that can help up assess the cache size in a future:
72-
(-> orchard.java/cache .keySet .size))
73-
74-
(def initializer
75-
(future
76-
(warmup-orchard-caches!)))
60+
(try
61+
;; This call removes the delay from the next `.prefix` completion.
62+
(compliment/completions ".sub")
63+
(catch Throwable t
64+
(println "Error during" `warmup-caches! ":" (str t)))))
65+
66+
(defonce ^:private warmup-once
67+
(.start (Thread. ^Runnable warmup-caches!)))
7768

7869
;;; Functionality for deferred middleware loading
7970
;;

test/clj/cider/nrepl_test.clj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,3 @@
77
(is (let [v (System/getenv "CLOJURE_VERSION")]
88
(println "Running on Clojure" (clojure-version))
99
(or (nil? v) (.startsWith ^String (clojure-version) v)))))
10-
11-
(deftest warmup-orchard-caches!
12-
@sut/initializer ;; Prevent concurrent calls to `sut/warmup-orchard-caches!`
13-
(testing "Can be executed without throwing exceptions"
14-
(is (pos? (sut/warmup-orchard-caches!))
15-
"Returns the keys count of the affected cache")))

0 commit comments

Comments
 (0)