clj-memory-meter icon indicating copy to clipboard operation
clj-memory-meter copied to clipboard

Anomalous measurements of instances of `clojure.lang.LongRange`

Open blosavio opened this issue 4 weeks ago • 0 comments

When invoking mm/measure on instances of clojure.lang.LongRange, I expect the memory usage to increase with increasing lengths. Instead, the return values are identical, regardless of the ending index.

(mm/measure (doall (range 3)) :debug true)
;; => "56 B"
(mm/measure (doall (range 99999)) :debug true)
;; => "56 B"

For both of the above cases, the :debug true prints to *out* merely:

root [clojure.lang.LongRange] 56 bytes (56 bytes)

Interestingly, measurement appears to work fine for clojure.lang.Range:

(mm/measure (doall (range 3.0)) :debug true)
;; "496 B"

... which prints to *out*

root [clojure.lang.Range] 496 bytes (56 bytes)
  |
  +--end [java.lang.Double] 24 bytes (24 bytes)
  |
  +--start [java.lang.Long] 24 bytes (24 bytes)
  |
  +--step [java.lang.Long] 24 bytes (24 bytes)
  |
  +--boundsCheck [clojure.lang.Range$1] 16 bytes (16 bytes)
  |
  +--_chunk [clojure.lang.ArrayChunk] 24 bytes (24 bytes)
  |
  +--_next [clojure.lang.Range] 328 bytes (56 bytes)
    |
    +--_chunk [clojure.lang.ArrayChunk] 24 bytes (24 bytes)
    |
    +--_next [clojure.lang.Range] 248 bytes (56 bytes)
      |
      +--start [java.lang.Long] 24 bytes (24 bytes)
      |
      +--_chunk [clojure.lang.ArrayChunk] 168 bytes (24 bytes)
        |
        +--array [java.lang.Object[]] 144 bytes (144 bytes)

I have not seen any errors or otherwise unexpected behavior.

Environment info: (clojure-version) ;; => "1.12.4"

$ java --version openjdk 11.0.29 2025-10-21

[com.clojure-goes-fast/clj-memory-meter "0.4.0"]

blosavio avatar Dec 17 '25 12:12 blosavio