Clojure

clojure.core/set should use transients

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.5, Release 1.6
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
  • Patch:
    Code
  • Approval:
    Ok

Description

CLJ-1384-p2 uses transients for both create and createWithCheck. This is consistent with the current implementation for map.

clojure.core/vec calls (more or less) PersistentVector.create(...), which uses a transient vector to build up the result.

clojure.core/set on the other hand, calls PersistentHashSet.create(...), which repeatedly calls .cons on a PersistentHashSet, with all the associated speed/GC issues.

Operation count now w/transients
set 5 1.771924 µs 1.295637 µs
into 5 1.407925 µs 1.402995 µs
set 1000000 2.499264 s 1.196653 s
into 1000000 0.977555 s 1.006951 s

Patch: CLJ-1384-p2.patch
Screened by: Stu

  1. CLJ-1384-p1.patch
    15/Mar/14 10:46 PM
    2 kB
    Gary Fredericks
  2. CLJ-1384-p2.patch
    27/Jun/14 12:57 PM
    4 kB
    Stuart Halloway
  3. set-bench.tar
    11/Apr/14 11:15 AM
    6 kB
    Ambrose Bonnaire-Sergeant

Activity

People

Vote (4)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: