Mojo RouterImpl's HashMap causes unnecessary gc due to boxing/unboxing |
||
Issue descriptionorg.chromium.mojo.bindings.RouterImpl uses a HashMap<Long, MessageReceiver> to store the callbacks for all Mojo method calls. Lint complains that this causes unnecessary garbage collection thrashing due to boxing/unboxing of the long map keys, and instead recommends to use an android.util.LongSparseArray. But LongSparseArray is probably not suitable either, since the documentation says it's "not intended to be appropriate for data structures that may contain large numbers of items"[1]. Instead, we probably want to use a specialized "LongHashMap" class which combines the benefits of both, such as [2]. In the meantime, the lint warning will be suppressed. [1]: http://developer.android.com/reference/android/util/LongSparseArray.html [2]: https://github.com/greenrobot/essentials/blob/master/java-essentials/src/main/java/org/greenrobot/essentials/collections/LongHashMap.java
,
Nov 14
Still valid, as RouterImpl still has a HashMap with boxed longs as keys. LongSparseArray may in fact be appropriate as the number of pending responses on an endpoint at any given time should not really grow too large. |
||
►
Sign in to add a comment |
||
Comment 1 by bugdroid1@chromium.org
, Apr 5 2016