clojure-dev

mfikes 2022-12-14T03:07:40.331239Z

I wonder if the perf of expressions like this are impacted by the IDrop stuff

(take 3 (filter even? (range 100000000)))

Alex Miller (Clojure team) 2022-12-14T03:50:59.466689Z

Because?

mfikes 2022-12-14T04:57:57.359719Z

Hunch is that this messes with chunking (`even?` is applied to a huge chunk). https://github.com/clojure/clojure/blob/e6fce5a42ba78fadcde00186c0b0c3cd00f45435/src/jvm/clojure/lang/LongRange.java#L120

mfikes 2022-12-14T04:58:24.179699Z

(count (chunk-first (range 100000000))) is 100000000

mfikes 2022-12-14T05:01:11.201439Z

In 1.11.1 this would be 32 and laziness would be preserved... while the change seems to make that expression be eager

Alex Miller (Clojure team) 2022-12-14T13:11:12.676299Z

Range never actually eagerly computed values, so nothing has changed there - it just makes one giant chunk rather than n

Alex Miller (Clojure team) 2022-12-14T13:12:36.934039Z

I did perf test the range changes in a variety of ways and it is much faster in some cases, like reduce and iteration (a wash in others)

Alex Miller (Clojure team) 2022-12-14T13:14:27.609529Z

filter is still making a chunk of 32

mfikes 2022-12-14T13:43:37.682159Z

Ahh, perhaps this isn't the case on Clojure master? If I evaluate (take 3 (filter even? (range 100000000))) in 1.12.1-alpha1, I think I get a huge chunk being evaluated...

mfikes 2022-12-14T13:46:04.361119Z

Here is a repro... if you evaluate (take 3 (filter (fn [x] (prn x) (even? x)) (range 100))) you will see 100 applications

Alex Miller (Clojure team) 2022-12-14T13:53:14.637009Z

I’ll take a look

👍 1
mfikes 2022-12-14T13:53:45.931099Z

Extracting a bit of the logic from filter this seems relevant: (let [r (range 100)] [(chunked-seq? r) (count (chunk-first r))]) -> [true 100]

💯 1
Alex Miller (Clojure team) 2022-12-14T20:52:09.271969Z

Rich and I talked about it today, I'm going to just fall back to making 32-element chunks in range for now, will target that at alpha2

😮 2
Alex Miller (Clojure team) 2022-12-14T20:52:15.092179Z

thanks for the question!

👍 1
➕ 1