RFR: 8337505: Footprint and startup regressions up to 20% in GUI apps

Phil Race prr at openjdk.org
Wed Oct 30 21:43:01 UTC 2024


On Tue, 29 Oct 2024 22:21:08 GMT, Phil Race <prr at openjdk.org> wrote:

>> https://bugs.openjdk.org/browse/JDK-8338677 already improved things for this so that's good.
>> 
>> This fix adds to it lazy initialisation of VarHandles in StrikeCache at the cost of some extra code.
>> Since these VarHandles get used more or less immediately on Linux this new fix won't further improve matters there
>> But should help on Mac where they aren't usually needed at startup
>> And Windows is somewhere in between.
>
>> I suspect dropping `static final` from these `VarHandle`-s would degrade performance, as some internal checks in `VHs` would not constant-fold.
>> 
>> Do you need these in isolation, or can you lazily-initialize them all at once? You can use "holder class" pattern like:
>> 
>> ```
>>   static class VHHolder {
>>     static final VarHandle xAdvanceHandle = ...
>>   }
>> ```
> 
> 
> 
>> I suspect dropping `static final` from these `VarHandle`-s would degrade performance, as some internal checks in `VHs` would not constant-fold.
>> 
>> Do you need these in isolation, or can you lazily-initialize them all at once? You can use "holder class" pattern like:
>> 
>> ```
>>   static class VHHolder {
>>     static final VarHandle xAdvanceHandle = ...
>>   }
>> ```
> 
> I've been told about this static final optimisation but I've never observed any measurable benefit in other code where I've tried hard to see it.
> Performance (runtime) isn't a huge concern for this code. Won't be noticed
> Start up is noticed. And on Windows *some* are used early but not all which is why I chose this approach

> @prrace even if not perf critical, every cpu cycle count, do not waste if possible!
> 
> I do recomment using the lazy holder singleton pattern:
> 
> ```
> protected final class VHHolder {
>     private final static vh...
> 
>     // END:
>     private final static VHHolder INSTANCE = new VHHolder();
> }
> 
> private static VHHolder holder = null;
> 
> static getVHHolder() {
>     // lazy pattern (synchronized if needed)
>    if (holder == null) holder = VHHolder.INSTANCE;
>    return holder;
> }
> ```
> 
> Or something like that...
> 
> My 2 cents


I would have to create a class per-varhandle. I really don't want to do that.

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

PR Comment: https://git.openjdk.org/jdk/pull/21748#issuecomment-2448431799


More information about the client-libs-dev mailing list