RFR: JDK-8322964 Optimize performance of CSS selector matching [v2]

John Hendrikx jhendrikx at openjdk.org
Fri Jan 12 14:08:36 UTC 2024


On Fri, 12 Jan 2024 12:20:22 GMT, Marius Hanl <mhanl at openjdk.org> wrote:

>> Thanks for having a look, it's good to have some more use cases from other applications!  The sets are used both for the style classes on `Node`s but also the set of style classes in CSS selectors (multiple style classes in  selectors are even more rare I think than multiple style classes on `Node`s).
>> 
>> I think from a performance perspective, `Duo` and `Hashless` are likely very closely matched, but I can do some testing in that area.  The reason I say this is that I only got a very minor boost from including `Duo`, but kept it because it is a bit more memory efficient.
>> 
>> If you want, I'm also curious about how many styles are used in your application (you can see this by looking at the size of `StyleClassSet#styleClasses` after all styles are loaded).
>
> I see, thanks for checking that out.
> 
> I checked the application, here is the result:
> After starting the app:
> ![image](https://github.com/openjdk/jfx/assets/66004280/623049ac-c525-4854-8f06-b9712de5d746)
> 
> After using it a little bit:
> ![image](https://github.com/openjdk/jfx/assets/66004280/cca4df47-829a-4d9b-b937-705b6c058172)
> 
> ---
> I also checked out Scenebuilder after using it a little bit:
> ![image](https://github.com/openjdk/jfx/assets/66004280/0f8992b5-1073-4c77-b906-356b86c61389)

Thanks, it looks like a bit less classes are in use when compared to JFXCentral (which has about 1000), but still quite a lot.  With `BitSet` that means if style classes are referenced that happen to have a high bit set, it creates an array to hold 400 bits (using 8 longs).  When few style classes are active, the sets provided by `FixedCapacitySet` will be often smaller and (due to the other optimizations as well) faster.  8 longs is sufficient to hold 8 or 16 style name references depending on the JVM (32/64 bit, compressed pointers y/n).

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1316#discussion_r1450495992


More information about the openjfx-dev mailing list