<< Back to previous view

[CLJ-1373] LazySeq should utilize cached hash from its underlying seq. Created: 09/Mar/14  Updated: 04/May/15

Status: Open
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Jozef Wagner Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: collections, performance

1.6.0 master SNAPSHOT

Attachments: File clj-1373-2.diff     File clj-1373.diff    
Patch: Code
Approval: Triaged


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

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

Comment by Jozef Wagner [ 09/Mar/14 9:20 AM ]

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

Comment by Alex Miller [ 04/May/15 9:34 AM ]

In this patch, can you update the else case (the original code) to use s rather than this, so seq() is not re-called?

Comment by Jozef Wagner [ 04/May/15 12:30 PM ]

Added patch clj-1373-2.diff that reuses s for else case.

Generated at Fri May 29 11:46:34 CDT 2015 using JIRA 4.4#649-r158309.