Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Improve Java parsing performance #237

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src-newer-jdks/orchard/java/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@
(when-let [^DocletEnvironment root (parse-java path (module-name klass))]
(try
(let [path-resource (io/resource path)]
(assoc (->> (.getIncludedElements root)
(filter #(#{ElementKind/CLASS
ElementKind/INTERFACE
ElementKind/ENUM}
(.getKind ^Element %)))
(keep #(parse-info % root))
(filter #(= klass (:class %)))
(first))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit better due to laziness, but it will still realize at least a 32-chunk of parse-infos before doing first on them.

(assoc (some #(when (#{ElementKind/CLASS
ElementKind/INTERFACE
ElementKind/ENUM}
(.getKind ^Element %))
(let [info (parse-info % root)]
(when (= (:class info) klass)
info)))
(.getIncludedElements root))
;; relative path on the classpath
:file path
;; Legacy key. Please do not remove - we don't do breaking changes!
Expand Down
16 changes: 8 additions & 8 deletions src-newer-jdks/orchard/java/parser_next.clj
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@
(when-let [^DocletEnvironment root (parse-java path (module-name klass))]
(try
(let [path-resource (io/resource path)]
(assoc (->> (.getIncludedElements root)
(filterv #(#{ElementKind/CLASS
ElementKind/INTERFACE
ElementKind/ENUM}
(.getKind ^Element %)))
(mapv #(parse-info % root))
(filterv #(= klass (:class %)))
(first))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of eagerness, this code invoked parse-info on every element of root even though we only need the first one that matches (= klass (:class %).

(assoc (some #(when (#{ElementKind/CLASS
ElementKind/INTERFACE
ElementKind/ENUM}
(.getKind ^Element %))
(let [info (parse-info % root)]
(when (= (:class info) klass)
info)))
(.getIncludedElements root))
;; relative path on the classpath
:file path
;; Legacy key. Please do not remove - we don't do breaking changes!
Expand Down
3 changes: 1 addition & 2 deletions src/orchard/java.clj
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@
[ns sym]
(when-let [ns (find-ns ns)]
(->> (vals (ns-imports ns))
(map #(member-info (-> ^Class % .getName symbol) sym))
(filter identity)
(keep #(member-info (-> ^Class % .getName symbol) sym))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is minor.

(distinct))))

(defn trim-one-dot
Expand Down