# KeyToHash possibly letting key interfaces escape to heap

**URL:** <https://discuss.dgraph.io/t/keytohash-possibly-letting-key-interfaces-escape-to-heap/8711>\
**Category:** Issues\
**Tags:** ristretto, status:accepted, kind:bug, priority:p1\
**Created:** [December 2, 2019, 5:49pm UTC](https://discuss.dgraph.io/t/keytohash-possibly-letting-key-interfaces-escape-to-heap/8711 "2019-12-02T17:49:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [December 2, 2019, 5:49pm UTC](https://discuss.dgraph.io/t/keytohash-possibly-letting-key-interfaces-escape-to-heap/8711/1 "2019-12-02T17:49:13Z")

</div>

**Moved from GitHub [ristretto/107](https://github.com/dgraph-io/ristretto/issues/107)**

_Posted by_ [karlmcguire](https://github.com/karlmcguire):

As brought up in the performance Gopher channel, since we’re using `interface{}` for keys, [this call to `keyToHash`](https://github.com/dgraph-io/ristretto/blob/master/cache.go#L166) is probably letting the interface escape to heap.

Solution: switch over to `string` or `[]byte` for public API calls.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [February 21, 2020, 8:02pm UTC](https://discuss.dgraph.io/t/keytohash-possibly-letting-key-interfaces-escape-to-heap/8711/2 "2020-02-21T20:02:53Z")

</div>

[martinmr](https://github.com/martinmr) _commented_ :

@karlmcguire should the change be for keys or keys and values?

---

<div class="post-metadata">

**Author:** ![LGalatin](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/lgalatin/32/2829_2.png) [@LGalatin](https://discuss.dgraph.io/u/LGalatin)\
**Post date:** [September 30, 2020, 11:15pm UTC](https://discuss.dgraph.io/t/keytohash-possibly-letting-key-interfaces-escape-to-heap/8711/3 "2020-09-30T23:15:58Z")

</div>

some of the issues are fixed by this PR: [Improve memory performance by martinmr · Pull Request #195 · dgraph-io/ristretto · GitHub](https://github.com/dgraph-io/ristretto/pull/195)
