I have a JavaFX Group
with a Path
Node added to it, to which I add data approximately 30 times per second. This causes my whole GUI to become very laggy and unresponsive after about a minute.
First, I add the path to the Group
like this:
root.getChildren().add(path);
Data is added like this:
while(true) {
// Calculate x and y...
path.getElements().add(new LineTo(x, y));
path.getElements().add(new MoveTo(x, y));
// Sleep 33 milliseconds...
}
If I do not add the path to the group, but still add data afterwards, the GUI remains responsive, so the performance issue seems to be when drawing the path's shape. Why? What can I do to improve the performance? Is this known to happen or am I doing something wrong? Thanks!
There is a known issue (creating paths is very slow) in JavaFX 2.1 related to Path performance and another, similar issue unresolved in JavaFX 2.2 (improve path rendering performance). There may be other issues if you check the JavaFX issue tracker system. For JavaFX8, which is currently under development, the performance of many elements has been vastly improved.
One alternate approach you may try is to use a Canvas rather than a Path. Depends on your use case though, for some use cases, this will be a suitable substitution, for others it won't.
If you can create a short reproducible test case and file a JavaFX issue for it, the JavaFX team will investigate any performance issues you are seeing and potentially address them if they are caused by the underlying system implementation.
You should also check your implementation for the following things:
Not saying your code has any of the above issues, just things to check.