Github user franz1981 commented on the issue:
https://github.com/apache/activemq-artemis/pull/1263
@michaelandrepearce Got it, there is another effective solution to this:
build an interner, similar to a StringInterner, but with a different hashed
logic in order to avoid the JVM duplicating autoboxed instances each time.
Few lines of code to explain it better:
```
//it will retain in LRU fashion the last 64 Long instances
LongInterner longCache = new LongInterner(64);
long id;
//instead of:
put(id , connection);
//interned instance
Long cachedId = longCache.intern(id);
put(cachedId, connection);
```
wdyt?
The caching/escape analysis are different things AFAIK:
- caching is performed by the library on long->Long, and put by the
compiler when autoboxing (eg
[Long::valueOf](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/lang/Long.java#837))
- [escape
analysis](http://docs.oracle.com/javase/7/docs/technotes/guides/vm/performance-enhancements-7.html#escapeAnalysis):
newly created Long instances no longer exists on the heap but being unpacked
on the stack if used temporary, but need to call by hand new Long(long),
bypassing the cached logic and do not retain it (seems not our case anyway)
eg
http://www.rationaljava.com/2015/12/how-long-does-it-take-jvm-to-effect.html
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---