Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

In reviewing some hashing stuff, I noticed that there are many places internal to Clojure that use maps initialized with PersistentHashMap.EMPTY. Many of these maps are likely to have a small number of entries such that a PersistentArrayMap might be more efficient.

These are the candidates:

`
src/jvm/clojure/lang/ARef.java
19:private volatile IPersistentMap watches = PersistentHashMap.EMPTY;

src/jvm/clojure/lang/Compiler.java
3009: IPersistentMap m = PersistentHashMap.EMPTY;
3819: KEYWORDS, PersistentHashMap.EMPTY,
3820: VARS, PersistentHashMap.EMPTY,
3964: IPersistentMap closes = PersistentHashMap.EMPTY;
3977: IPersistentMap keywords = PersistentHashMap.EMPTY;
3978: IPersistentMap vars = PersistentHashMap.EMPTY;
5121: ,CLEAR_SITES, PersistentHashMap.EMPTY
7259: KEYWORDS, PersistentHashMap.EMPTY,
7260: VARS, PersistentHashMap.EMPTY
7418: IPersistentMap opts = PersistentHashMap.EMPTY;
7475: IPersistentMap fmap = PersistentHashMap.EMPTY;
7522: KEYWORDS, PersistentHashMap.EMPTY,
7523: VARS, PersistentHashMap.EMPTY,
7912: ,CLEAR_SITES, PersistentHashMap.EMPTY

src/jvm/clojure/lang/LispReader.java
755: RT.map(GENSYM_ENV, PersistentHashMap.EMPTY));

src/jvm/clojure/lang/MultiFn.java
39: this.methodTable = PersistentHashMap.EMPTY;
41: this.preferTable = PersistentHashMap.EMPTY;
49: methodTable = methodCache = preferTable = PersistentHashMap.EMPTY;

src/jvm/clojure/lang/Var.java
48: final static Frame TOP = new Frame(PersistentHashMap.EMPTY, null);
175: setMeta(PersistentHashMap.EMPTY);
341: IPersistentMap ret = PersistentHashMap.EMPTY;
`

Approach: Two possible approaches - initialize to PersistentArrayMap.EMPTY or call RT.map(). The latter requires function invocation so is slightly slower, but has the benefit of localizing map construction into a single place.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1376 (reported by alexmiller)
...