JavaFX 2路径绘制性能 [英] JavaFX 2 path drawing performance

查看:66
本文介绍了JavaFX 2路径绘制性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaFX Group ,其中添加了 Path 节点,向该节点添加了大约30次数据每秒。这导致我的整个GUI在大约一分钟后变得非常缓慢且无响应。
首先,我将路径添加到 Group 像这样:

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);

像这样添加数据:

while(true) {
    // Calculate x and y...

    path.getElements().add(new LineTo(x, y));
    path.getElements().add(new MoveTo(x, y));

    // Sleep 33 milliseconds...
}

如果我没有将路径添加到组中,但是之后仍然添加了数据,则GUI仍会响应,因此性能问题似乎出在绘制路径的形状时。为什么?我该怎么做才能提高性能?这是已知发生的还是我做错了什么?
谢谢!

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!

推荐答案

存在一个已知问题(创建路径非常慢),与路径性能相关的JavaFX 2.1和JavaFX 2.2中未解决的另一个类似问题(提高路径渲染性能)。如果您检查 JavaFX问题跟踪系统,则可能还有其他问题。对于当前正在开发的JavaFX8,许多元素的性能已经已大大改进

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.

如果您可以创建一个简短的可复制测试用例并为其提交JavaFX问题,JavaFX团队将调查您看到的任何性能问题,如果它们是由底层系统实现引起的,则有可能解决。

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:


  1. 请勿在JavaFX线程上调用睡眠。

  2. 不要在JavaFX线程上进行任何处理器密集型操作。

  3. 不要在JavaFX线程上执行阻塞I / O。

  4. Don'

  5. 从另一个线程在SceneGraph中读取或写入对象时,请使用 Platform.runLater


  1. Do not call sleep on the JavaFX thread.
  2. Don't do anything processor intensive on the JavaFX thread.
  3. Don't perform blocking I/O on the JavaFX thread.
  4. Don't place tens of thousands of nodes in the SceneGraph or a Path.
  5. When reading or writing objects in the SceneGraph from another thread, use Platform.runLater.
  6. Don't call Platform.runLater too often or you will end up overloading the event handling system.

不要过多地调用Platform.runLater,否则最终会使事件处理系统超载。上述问题,只是需要检查的东西。

Not saying your code has any of the above issues, just things to check.

这篇关于JavaFX 2路径绘制性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆