Reputation: 4208
I want to visualize a static chart with 10 series each having 10'000 points using JavaFX.
After my first tests I'm a bit worried about the performance of the JavaFX chart API, especially about the constructor new XYChart.Series<>(...)
which takes 3 minutes of initialization for 100'000 data points.
If you don't believe me, run the code below:
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 so long and how can one work around this?
Or is there a way to use the JavaFX charts without Observables?
Upvotes: 4
Views: 2359
Reputation: 159341
It looks like series creation was a performance issue which was fixed between Java 8u25 and Java 8u40.
I ran your application on 8u25 and got the following result:
Time for creating list: 59 ms
Time for creating series: 135896 ms
Upgrading to 8u40 and running again, I got the following result:
Time for creating list: 66 ms
Time for creating series: 80 ms
So, just update to the latest Java version and you should be good to go.
Upvotes: 4