Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8322964

Optimize performance of CSS selector matching

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx23
    • None
    • javafx
    • None
    • b21

      After looking into the regression caused by https://bugs.openjdk.org/browse/JDK-8304959, which was fixed with https://bugs.openjdk.org/browse/JDK-8322795, there is room for more improvement in selector matching speed.

      After analysis of the sets that hold the style classes for selectors and nodes, it was discovered that these generally are very small (one or two elements, rarely three, and extremely rarely 4 or more). It makes sense to optimize for these cases.

      Another reason the optimization will be good is that the current approach relies on a non-sparse bit set. Given that a good sized JavaFX application can have over 1000 style classes, these bit sets can contain up to 1000 bits, with only one or two or three set bits. This approach is not very scalable when even more style classes may be present.

      On top of that, the whole StyleClass wrapper is fairly useless (its presence is required for assigning a fixed bit position for the bit sets). It can be eliminated from all the hot code paths, but will need to be maintained as it is part of public API (although said API could be deprecated).

      Tests with the JFXCentral application show that it is possible to make CSS selector matching almost twice as fast using an approach of specialized append only fixed size sets. These sets can be special cased for various sizes, provide a low memory foot print (no wrapper per entry), are sparse (only contains "set" bits), and can provide specialized reversed containsAll functionality (isSuperSetOf) that does not require the creation of an iterator. Furthermore, they can be made read only by "freezing" them, avoiding the need for a Collections.unmodifiableSet wrapper.

            jhendrikx John Hendrikx
            jhendrikx John Hendrikx
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: