How to improve JavaFX chart performance?

I want to visualize a static chart with 10 rows, each of which has 10,000 points using JavaFX. After my first tests, I'm a little worried about the performance of the JavaFX diagram APIs, especially the constructor new XYChart.Series<>(...), which takes 3 minutes to initialize for 100,000 data points.

If you do not believe me, run the following code:

public static final int SIZE = 100000;

public static void main(String[] args) {
    List<XYChart.Data<Integer, Integer>> data = new ArrayList<>(SIZE);

    measureTime("creating list", () -> {
        for (int i=0; i<SIZE; i++) {
            data.add(new XYChart.Data<>(i, i));
        }
    });

    measureTime("creating series", () -> {
        new XYChart.Series<>(FXCollections.observableList(data));
    });
}

public static void measureTime(String msg, Runnable f) {
    long start = System.nanoTime();
    f.run();
    long end = System.nanoTime();

    System.err.println("Time for " + msg + ": " + (end - start) / 1000000 + " ms");
}

These are the results on my computer:

Time for creating list: 62 ms
Time for creating series: 173555 ms

Why does this initialization take too long and how can I get around this?

Or is there a way to use JavaFX diagrams without Observables?

+4
source share
1 answer

, , ​​ Java 8u25 Java 8u40.

8u25 :

Time for creating list: 59 ms 
Time for creating series: 135896 ms

8u40 , :

Time for creating list: 66 ms
Time for creating series: 80 ms

, Java, .

+4

All Articles