One of my least proud (most proud?) hacks when working with very large data sets is something like this
Map<Integer, Integer> intCache = new HashMap<>();
while (loading) {
Integer feild1 = intCache.computeIfAbsent(getField1(), (i)->i);
}
This is a terrible thing that shouldn't be as useful as it is to us... but it is really useful. We have a bunch of objects that can optionally have Integer values (hence a null is valid) but those int values are frequently the same.This saves a bunch of memory and ultimately GC pressure as a result.
Valhalla can't come soon enough for us.
I mean FWIW this looks to me much like the sort of hacks I had to get into last time I worked with Java so I can't really blame you....
> Valhalla can't come soon enough for us.
This will be interesting to see for sure, I think it will raise the bar for competitors as well; .NET GC has lingered in some ways for a while in progressing [0][1], there is a long standing github discussion around a lower latency GC where there is a potential alternative [2] but nothing really signaling that it could be integrated in future as an option. Valhalla might finally put enough pressure on microsoft to do something about the lag in this space.
[0] - The inferred stackalloc stuff on the JIT level is awesome but I don't count that as improvement to actual GC
[1] - Pinned allocs took a long time and we still can't get aligned pinned allocs (have to manually pad instead)
I do something similar for Java Time local dates. Financial data in particular has lots of redundant date info and benefits from being memoized. Converting to epoch millis also works.