Use PAM for small maps when assigned to a var rather than always using PHMs

Description

I'm reproposing the fix I implemented for http://dev.clojure.org/jira/browse/CLJ-944 a while ago as an enhancement rather than as a defect.

Currently when a map is used as the value of a `def` expression, unless it's an empty map, it will always be a PersistentHashMap even if it's a small map.

user=> (def a {:foo :bar}) #'user/a user=> (class a) clojure.lang.PersistentHashMap

The current patch makes makes small maps be compiled to PAMs, consistently with how it's handled in lexical contexts, only using PHMs when the number of elements is above the threshold

user=> (def a {:foo :bar}) #'user/a user=> (class a) clojure.lang.PersistentArrayMap user=> (class (let [a {:foo :bar}] a)) clojure.lang.PersistentArrayMap user=> (def a {0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) #'user/a user=> (class a) clojure.lang.PersistentHashMap

Environment

None

Attachments

1
  • 15 Nov 2014, 06:14 PM

Activity

Show:

Nicola Mometto March 9, 2015 at 7:40 PM

Alex Miller December 8, 2014 at 3:47 PM

We're just splitting the ticket apart, maps will be a separate ticket/patch.

Nicola Mometto December 8, 2014 at 3:19 PM

This is now out of scope for https://clojure.atlassian.net/browse/CLJ-1517#icft=CLJ-1517 now that's focused only on vectors.

Alex Miller November 15, 2014 at 6:17 PM

This might be subsumed under the small collections CLJ-1517, not sure.

Declined

Details

Assignee

Reporter

Patch

Code

Priority

Created November 15, 2014 at 6:14 PM
Updated March 9, 2015 at 7:40 PM
Resolved March 9, 2015 at 7:40 PM

Flag notifications