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

Remove laziness in Slamhound's "get-available-classes" #184

Closed
wants to merge 3 commits into from

Conversation

plexus
Copy link
Contributor

@plexus plexus commented Jan 20, 2017

Once the classpath gets big enough, this would cause a stack overflow, which
from clj-refactor simply shows up as a timeout.

Instead use transducers over lists as much as possible. Since the collection of
available classes is only ever traversed sequentially, this provides the best
performance as well.

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s) --> functionality hasn't changed, so no tests added
  • All tests are passing (run lein do clean, test)
  • Code inlining with mranderson works and tests pass with inlined code (run ./build.sh install -- takes a long time)
  • You've updated the changelog (if adding/changing user-visible functionality) --> no user visible changes
  • You've updated the readme (if adding/changing user-visible functionality) --> no user visible changes

Thanks!

Once the classpath gets big enough, this would cause a stack overflow, which
from clj-refactor simply shows up as a timeout.

Instead use transducers over lists as much as possible. Since the collection of
available classes is only ever traversed sequentially, this provides the best
performance as well.
(catch Exception e [])))) ; fail gracefully if jar is unreadable

(defmethod path-class-files :dir
;; Dispatch directories and files (excluding jars) recursively.
[#^File d #^File loc]
(let [fs (.listFiles d (proxy [FilenameFilter] []
(accept [d n] (not (jar? (file n))))))]
(reduce concat (for [f fs] (path-class-files f loc)))))
Copy link
Member

Choose a reason for hiding this comment

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

this line was actually asking for trouble..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup.

@plexus
Copy link
Contributor Author

plexus commented Jan 22, 2017

Tests are all green, including with mranderson. Anything I can do to move this forward? Thx!

(into (map #(System/getProperty %) ["sun.boot.class.path"
"java.ext.dirs"
"java.class.path"])
(map #(.getName %) (cp/classpath-jarfiles))))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied this logic over, although it seems strange to me that this is really the way to get the full classpath.

@benedekfazekas
Copy link
Member

this looks awesome @plexus. give me a few days tops to have a proper look tho

@benedekfazekas
Copy link
Member

actually one small thing: can you pls add a one liner to the change log?

@plexus
Copy link
Contributor Author

plexus commented Jan 22, 2017

Sure thing! If it's ok I'm gonna push a few more small cleanups, like replace #^ with ^.

@benedekfazekas
Copy link
Member

👍

FileNameFilter is an interface, so reify does the job just fine, no need for
proxy.
plexus added a commit to plexus/refactor-nrepl that referenced this pull request Jan 22, 2017
Error inherits directly from Throwable, so Errors are not Exceptions, they need
to be handled separately. This category includes RuntimeError,
StackOverflowError, and NoClassDefFoundError.

In regular applications you would not catch these, but in our case letting them
bubble means the nREPL handler dies without returning a response, causing the
client to assume that the operation is taking too long and time out, without any
useful feedback.

This is bad UX, and it makes it hard to diagnose and debug problems like clojure-emacs#184.
At least this way the user will see a stack trace that hints at the problem.
@benedekfazekas
Copy link
Member

great work @plexus! thanks again for all your PRs this WE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants