Records do not cache hash like normal maps

Description

Records do not cache their hash codes like normal Clojure maps, which affects their performance. This problem has been fixed in CLJS, but still affects JVM CLJ.

Approach: Cache hash values in record definitions, similar to maps.

Timings:

coll

1.9.0-master

1.9.0-master+patch

small record

90 ns

7 ns

big record

446 ns

8 ns

Patch: clj-1224-3.patch

Screened by: Alex Miller

Also see: http://dev.clojure.org/jira/browse/CLJS-281

Environment

None

Attachments

5

Activity

Alex Miller September 6, 2016 at 8:10 PM

Added clj-1224-3.patch - identical to prior but uses zero? rather than = 0 at Rich's request. Attribution retained.

Nicola Mometto July 29, 2015 at 10:06 AM

Updated patch takes into account Alex's last notes

Alex Miller July 29, 2015 at 12:18 AM

Equivalent change in hashCode too.

Alex Miller July 29, 2015 at 12:17 AM

Hey Nicola, two comments on the hasheq/hashcode impl:

1) I don't think there's any reason to use == in the check instead of =, and = seems better (I think the resulting bytecode is same either way though).

2) The generated bytecode in these cases will call getfield twice in the cached case (once for the check, and once for the return):

Letting a local will avoid that:

Output bytecode:

For me, this was about 2% faster in bench too.

Alex Miller July 18, 2015 at 4:30 AM

Moving back to vetted for screening

Completed

Details

Assignee

Reporter

Approval

Patch

Priority

Fix versions

Created June 24, 2013 at 5:10 PM
Updated September 7, 2016 at 8:56 PM
Resolved September 7, 2016 at 8:56 PM