# JUCE HashMap performance

**URL:** <https://forum.juce.com/t/juce-hashmap-performance/17071>\
**Category:** General JUCE discussion\
**Created:** [April 1, 2016, 6:01pm UTC](https://forum.juce.com/t/juce-hashmap-performance/17071 "2016-04-01T18:01:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [April 1, 2016, 6:01pm UTC](https://forum.juce.com/t/juce-hashmap-performance/17071/1 "2016-04-01T18:01:14Z")

</div>

I still use the HashMap even though it's been somewhat obsoleted by std::map\<\> because std::map\<\> drives me bonkers that [] adds items to the map.

Anyway, HashMap was giving me some performance issues. My Key was a class that contains 4 Strings

Could:

```
ValueType operator[] (KeyTypeParameter keyToLookFor) const
bool contains (KeyTypeParameter keyToLookFor) const
```

Be changed to:

```
ValueType operator[] (const KeyTypeParameter& keyToLookFor) const
bool contains (const KeyTypeParameter& keyToLookFor) const
```

It stops a lot of Strings from being constructed and deconstructed for me.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 4, 2016, 8:58am UTC](https://forum.juce.com/t/juce-hashmap-performance/17071/2 "2016-04-04T08:58:26Z")

</div>

Sure, happy to tweak that!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 4, 2016, 9:19am UTC](https://forum.juce.com/t/juce-hashmap-performance/17071/3 "2016-04-04T09:19:25Z")

</div>

..actually, surely it already handles that? The KeyTypeParameter uses&nbsp;PARAMETER\_TYPE which is supposed to choose the best form for passing that type as a parameter. Are you sure it's copying it?

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [April 5, 2016, 3:02am UTC](https://forum.juce.com/t/juce-hashmap-performance/17071/4 "2016-04-05T03:02:48Z")

</div>

You are right, it's already handled in that template magic.&nbsp;

Maybe I didn't have the reference on my hash function, that could have been the issue.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 5, 2016, 7:45am UTC](https://forum.juce.com/t/juce-hashmap-performance/17071/5 "2016-04-05T07:45:45Z")

</div>

std::unordered\_map FTW !
