Skip to content

Commit

Permalink
Remove costly io/resource lookup that wasn't doing anything
Browse files Browse the repository at this point in the history
The `immutable-source-file?` check is used in `class-info` to know if it makes
sense to invalidate a cache entry based on modification time. This check uses
the `:path` it is given to see if the resource is inside a jar or not.

This `:path` comes from `orchard.java.{parser,legacy-parser}`, and is attained
by calling `(.getPath (io/resource ...))`. This means it is either an absolute
path on the filesystem, or it is a `file:..` URL pointing to a JAR.

```clojure
(io/resource "lambdaisland/witchcraft.clj")
;;=> #java.net.URL "file:/srv/mc/witchcraft/src/lambdaisland/witchcraft.clj"

(.getPath (io/resource "lambdaisland/witchcraft.clj"))
;;=> "/srv/mc/witchcraft/src/lambdaisland/witchcraft.clj"

(io/resource "clojure/lang/RT.class")
;;=> #java.net.URL "jar:file:/root/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar!/clojure/lang/RT.class"

(.getPath (io/resource "clojure/lang/RT.class"))
;;=> "file:/root/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar!/clojure/lang/RT.class"
```

Passing these things to `io/resource` again makes no sense, because these are
absolute paths/urls, they can't be resolved relative to the classpath. This will
always return nil.

```clojure
(io/resource "file:/root/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar!/clojure/lang/RT.class")
;;=> nil
```

This check is performed whether the class-info is cached already or not, causing
a full classpath scan on every call.

The net effect is that depending on circumstances cider-nrepl's "classpath" op
can get extremely slow, around 10~20 seconds to analyze all stack frames and
return a result, which means that the error buffer will only pop up 10~20
seconds after evaluating a form which causes an error.
  • Loading branch information
plexus committed Sep 18, 2021
1 parent ca5fae9 commit c71adc3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* `orchard.namespace` functionality is now parallelized when possible.

### Bugs Fixed

* [#124](https://github.com/clojure-emacs/orchard/pull/124): Remove costly `io/resource` lookup that wasn't doing anything

## 0.7.1 (2021-04-18)

### Bugs Fixed
Expand Down
7 changes: 3 additions & 4 deletions src/orchard/java.clj
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,9 @@
returns true if no source file is available, or if the source file is in a
jar/zip archive."
[info]
(let [path (:file info)
src (when path (io/resource path))]
(or (not src)
(re-find #"\.(jar|zip)!" (str src)))))
(let [path (:file info)]
(or (not path)
(re-find #"\.(jar|zip)!" (str path)))))

(defn class-info
"For the class symbol, return (possibly cached) Java class and member info.
Expand Down

0 comments on commit c71adc3

Please sign in to comment.