RFR: 5660: Lazy initialize timestamp unit description
Henrik Dafgård
hdafgard at openjdk.java.net
Wed Dec 11 16:26:38 UTC 2019
On Wed, 11 Dec 2019 15:35:41 GMT, Marcus Hirt <hirt 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?
Using an AtomicReference for the description would add an allocation overhead of around 3% for rules evaluations. I'm not sure that that's cheap enough for the cost. Another option is to remove the description as a field entirely, and always re-create it when asked.
-------------
PR: https://git.openjdk.java.net/jmc/pull/15
More information about the jmc-dev
mailing list