Uploaded image for project: 'Clojure'
  1. CLJ-1373

LazySeq should utilize cached hash from its underlying seq.

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: None
    • Fix versions: None
    • Environment:

      1.6.0 master SNAPSHOT

    • Approval:
      Triaged
    • Patch:
      Code

      Description

      Even if underlying seq contains a cached hash, LazySeq computes it every time.

      user=> *clojure-version*
      {:major 1, :minor 7, :incremental 0, :qualifier "master", :interim true}
      user=> (def a (range 100000))
      #'user/a
      user=> (time (hash a))
      "Elapsed time: 21.812 msecs"
      375952610
      user=> (time (hash a))        ;; hash is cached
      "Elapsed time: 0.036 msecs"
      375952610
      user=> (def b (seq a))
      #'user/b
      user=> (time (hash b))
      "Elapsed time: 0.042 msecs"   ;; uses cached hash
      375952610
      user=> (def c (lazy-seq b))
      #'user/c
      user=> (time (hash c))        ;; SHOULD use underlying hash
      "Elapsed time: 27.758 msecs"
      375952610
      user=> (time (hash c))        ;; SHOULD use underlying hash
      "Elapsed time: 17.846 msecs"
      375952610
      

      Approach: If seq produced by LazySeq implementing IHashEq, use it to calculate the hasheq().
      Patch: clj-1373.diff

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              wagjo Jozef Wagner
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: