RFR: 5660: Lazy initialize timestamp unit description

Marcus Hirt hirt at openjdk.java.net
Wed Dec 11 15:36:11 UTC 2019


On Wed, 11 Dec 2019 01:24:54 GMT, Henrik Dafgård <hdafgard at openjdk.org> wrote:

> Creating a string description for each timestamp unit instance is far too expensive since we have to create a new unit for e.g. each duration comparison. So rules that perform such comparisons cause a lot of unnecessary allocations, on my local machine I estimate that this will reduce total allocations by around 50% for rules evaluations.
> 
> This doesn't really fix JMC-5660, but will reduce the performance cost until we get a more proper fix for this bug.

core/org.openjdk.jmc.common/src/main/java/org/openjdk/jmc/common/unit/TimestampUnit.java line 226:

> 225: 	public String getLocalizedDescription() {
> 226: 		if (unitDescription == null) {
> 227: 			String multiplier = timeOffsetUnit.asWellKnownQuantity().displayUsing(IDisplayable.EXACT);

This makes this class thread unsafe, in the sense that there can be many local copies made of the unitDescription if used concurrently from multiple threads without any safety measures. Would an atomic reference be too expensive?

-------------

PR: https://git.openjdk.java.net/jmc/pull/15


More information about the jmc-dev mailing list