5 ms·
> If there was only a library that did date manipulation and arithmetic with longs instead of Instant :( You can always pass around long timestamps and just co
by nicktelford 6y ago
> If there was only a library that did date manipulation and arithmetic with longs instead of Instant :(
You can always pass around long timestamps and just convert to Instant whenever you need to do any date/time processing. Provided the Instant doesn't escape the method it's allocated in, it should be optimized via inlining and Scalar Replacement so that it doesn't generate garbage. Of course, you'd be adding in the overhead of dividing up your long in to seconds/nanos each time.
Note: if this doesn't work on OpenJDK, try GraalVM: it's Partial Escape Analysis should do a better job at finding ways of eliding heap allocations.
- haxen 6y agoThe worst things happen when value objects are stuck on the heap for a while and then turn into garbage when the value is updated. Escape Analysis doesn't help there, only a good GC can help.