question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VirtualizedScrollPane causes high CPU and GPU on idle with 125% screen scaling

See original GitHub issue

When using a control embedded inside a VirtualizedScrollPane with the upcoming release 16 of JavaFX, then it is possible under specific circumstances that the method layoutChildren() becomes perpetually invoked, causing high CPU and GPU usage even when the application is idle.

These conditions are:

  • Using openJFX 16 or higher at runtime
  • The effective screen scale at which the window is rendered is not a multiple of 100% (i.e. 125%, 150% or 175%, etc…).
  • The horizontal scrollbar is displayed.

The following code sample illustrates the issue, when run under javafx 16, with for instance a 125% scale (you can force it with -Dglass.win.uiScale=1.25 or -Dglass.gtk.uiScale=1.25, on windows or linux, respectively):

public class TextScroll extends Application {
    private final static String LONG_LINE_OF_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
            "Nulla viverra fringilla dictum. Integer faucibus laoreet nulla eget vehicula. " +
            "Vivamus et arcu eget metus interdum tincidunt ac sed libero. Phasellus vestibulum" ;

    @Override
    public void start(Stage stage) throws Exception {
        var textArea = new CodeArea();
        textArea.replaceText(LONG_LINE_OF_TEXT);
        Scene scene = new Scene(new VirtualizedScrollPane<>(textArea), 800, 600);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

The root cause for this, is that the VirtualizedScrollPane request a layout when the height of the horizontal scroll bar changes but in the course and the layout, the calculated value for this height changes, which in turns triggers a request layout, etc…

This is due to the fact that a bug was fixed in JavaFX 16 (https://bugs.openjdk.java.net/browse/JDK-8211294) where the mechanism which snaps coordinates to actual pixels on screen with a non integer scale factor was broken; this is now fixed in javaFX, but Flowless remains unaware of the need for enforcing snapping, which causes some coordinates calculated in Flowless to be rounded differently that their equivalent in JavaFX; in this case this is what caused the scrollbar height to be different in two nested calls to layoutChildren, and lead to the constant layout.

A solution is to use snapSize() method to ensure height and width are snapped (i.e. ceil’d) to pixels consistently with JavaFX.

(NB: Ideally, we’d want to use snapSizeX() and snapSizeY() instead of the deprecated snapSize() so that we properly support non square screen ratio, but this is not available in JavaFX 8 that Flowless is built against.)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Jugencommented, Feb 24, 2021

Hey Fred, thanks for the prompting … 0.6.3 has been released now. May take a day or two to appear on Maven though. RichTextFX may follow in the next week or two …

1reaction
Jugencommented, Jan 19, 2021

Hi @fthevenet, thanks for the detailed bug report.

I’m not the original author but I am the current maintainer, so if you submit a PR with your suggestion I’ll gladly merge it. Otherwise if you could point out the exact code that needs to change I can also submit the PR.

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flowless/CHANGELOG.md at master · FXMisc/Flowless · GitHub
VirtualizedScrollPane causes high CPU and GPU on idle with 125% screen scaling #81. Merged pull requests: Scrollbars height/width ceiled to nearest pixel if ......
Read more >
High CPU usage in DWM & interrupts when screen in standby
The issue of high CPU usage in DWM during idle has been discussed before but the circumstances here are different and I have...
Read more >
upgrade typescript and related things to from typescript 4.6.x to 4.7.x ...
VirtualizedScrollPane causes high CPU and GPU on idle with 125% screen scaling, 6, 2021-01-19, 2022-08-04 ; Introduce negative checks, just before each access....
Read more >
The flowless from FXMisc - Coder Social
VirtualizedScrollPane causes high CPU and GPU on idle with 125% screen scaling. When using a control embedded inside a VirtualizedScrollPane with the ...
Read more >
Flowless - Efficient VirtualFlow for JavaFX - JavaRepos
VirtualizedScrollPane causes high CPU and GPU on idle with 125% screen scaling · Using openJFX 16 or higher at runtime · The effective...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found