Clojure

LazySeq should utilize cached hash from its underlying seq.

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Environment:
    1.6.0 master SNAPSHOT
  • Patch:
    Code
  • Approval:
    Triaged

Description

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

user=> (def a (range 100000))
#'user/a
user=> (time (hash a))
"Elapsed time: 46.904273 msecs"
375952610
user=> (time (hash a)) ;; RECOMPUTE
"Elapsed time: 10.879098 msecs"
375952610
user=> (def b (seq a))
#'user/b
user=> (time (hash b))
"Elapsed time: 10.572522 msecs"
375952610
user=> (time (hash b)) ;; CACHED HASH
"Elapsed time: 0.024927 msecs"
375952610
user=> (def c (lazy-seq b))
#'user/c
user=> (time (hash c))
"Elapsed time: 12.207651 msecs"
375952610
user=> (time (hash c))
"Elapsed time: 10.995798 msecs"
375952610

Activity

Hide
Jozef Wagner added a comment -

Added patch which checks if underlying seq implements IHashEq and if yes, uses that hash instead of recomputing.

Show
Jozef Wagner added a comment - Added patch which checks if underlying seq implements IHashEq and if yes, uses that hash instead of recomputing.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: