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

[New REPL Window] REPL window freezes when the evaluation takes a long time #128

Closed
PEZ opened this issue Feb 19, 2019 · 2 comments
Closed

Comments

@PEZ
Copy link
Collaborator

PEZ commented Feb 19, 2019

When evaluating something that takes ”a sufficiently long time” to evaluate, the REPL window freezes. Evaluating the same thing inline works.

** REPRO **

Below is a naïve implementation of Eratosthenes Sieve. When evaluating the top-level form in that comment form in the REPL window (ctrl+alt+v alt+space) for n = 1000000 on my machine the REPL window never returns with the answer and becomes totally unresponsive.

(defn not-divisible-by [n d]
  (when-not (integer? (/ n d))
    n))

(defn sieve [n]
  (loop [found-primes [2]
         candidates (range 3 (inc n))]
    (let [highest-found-prime (last found-primes)
          remaining (->> candidates
                         (map #(not-divisible-by % highest-found-prime))
                         (remove nil?))]
      (if (= remaining candidates)
        (concat found-primes candidates)
        (recur (conj found-primes (first remaining)) (rest remaining))))))

(comment
  (sieve 1000000))

Again, evaluating the same form inline (ctrl+alt+v space), eventually, the results will be delivered.

Also, closing the REPL window and reopening it again works as a fix for getting the window back in operation.

@PEZ
Copy link
Collaborator Author

PEZ commented Feb 20, 2019

Update: It doesn't seem to be about how long time the evaluation takes. If I wrap my run of this test in (time), like so:

eratosthenes=> (time (str "mine: " (count (sieve-refined 1000000)) " primes"))
"Elapsed time: 7845.699169 msecs"
"mine: 78498 primes"

I do get the prompt back (even running this for primes up to 1,000,000).

So now I am guessing it is that the REPL Window chokes on the size of the results.

@cfehse
Copy link
Contributor

cfehse commented Oct 29, 2019

So now I am guessing it is that the REPL Window chokes on the size of the results.

This is exactly what happens. The whole output is processed through the Scanner.processLine() method which takes a awful long time.

@cfehse cfehse mentioned this issue Oct 29, 2019
18 tasks
cfehse pushed a commit to cfehse/calva that referenced this issue Oct 30, 2019
@cfehse cfehse mentioned this issue Oct 30, 2019
18 tasks
PEZ pushed a commit that referenced this issue Oct 30, 2019
@PEZ PEZ closed this as completed in b32fe13 Nov 2, 2019
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

No branches or pull requests

2 participants